2016-10-28 31 views
0

我想写一个闪亮的应用程序,它将一个文件作为输入并将该文件中的数据上传到bigquery表中,其中一些其他内容将继续。在将数据存入我的应用程序方面,一切似乎都工作正常,但是当我尝试将数据上传到bigquery时,没有任何反应。没有错误信息,只是没有。如何从闪亮的表格写入bigquery表格?

我可以自己运行代码,它执行得很好。由于无法写入公共数据集,因此我无法找出如何创建可重复使用的示例,但我在下面列出了我的代码。

附加信息:

  • 工作目录包含了我.httr-OAuth的文件
  • 数据是在我闪亮的应用程序可见

请让我知道如果有什么东西我可以补充,使这个问题更容易回答。谢谢。

############# UI ############ 
# 

library(shiny) 

shinyUI(fluidPage(

    # Application title 
    titlePanel("Upload"), 

    # Sidebar with a slider input for number of bins 
    sidebarLayout(
    sidebarPanel(
     fileInput('list', 'Choose file to upload', 
       accept = c(
        'text/csv', 
        'text/comma-separated-values', 
        '.csv' 
       )), 
     tags$hr(), 
     textInput('sql', 'Or give a query to get the customer_ids you want'), 
     tags$hr(), 
     actionButton('go', 'Go') 
    ), 

    # Show a plot of the generated distribution 
    mainPanel(
     tableOutput('log') 
    ) 
) 
)) 


############# server ############## 

### setting up the environment 
library(shiny) 
library(data.table) 
library(bigrquery) 

### setting up the constants 
project <- 'xxxxxxx' 
dest_dataset <- 'temp' 
dest_table <- 'custs_hash' 
cd <- 'CREATE_IF_NEEDED' 
wd <- 'WRITE_TRUNCATE' 

options(shiny.maxRequestSize = 100*1024^2) 


shinyServer(function(input, output) { 

    logs <- eventReactive(input$go, { 
    inFile <- input$list 
    dat <- fread(inFile$datapath) 
    dat <- head(dat) 
    return(list(dat = dat)) 
    }) 

    upload <- eventReactive(input$go, { 
    data <- dat()$dat 
    ins <- insert_upload_job(project, dataset = dest_dataset, table = dest_table, values = data, 
          create_disposition = cd, write_disposition = wd) 
    return(list(ins = ins)) 
    }) 

    output$log <- renderTable(logs()$dat) 

}) 
+0

我没有看到'upload' eventReactive正在您的代码中的任何地方使用/调用。 –

+0

我不确定'upload' eventReactive是什么意思。这是一个特殊功能吗?服务器中的日志功能能够检索输入文件并将其加载到我的闪亮会话中。这是一回事吗? – nFrain

+1

你有'上传< - eventReactive(...)'。请注意,除非使用'upload()'调用它,否则eventReactive将不会自行运行。 “日志”工作的原因是因为你在'renderTable'中调用它。 –

回答

0

eventReactive返回反应表达式对象。像其他被动对象一样,你需要明确地称它为一个函数。否则它不会自行运行。

所以在你的情况下,你有upload <- eventReactive(...),那么你需要使用upload()来调用它。