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)
})
我沒有看到'upload' eventReactive正在您的代碼中的任何地方使用/調用。 –
我不確定'upload' eventReactive是什麼意思。這是一個特殊功能嗎?服務器中的日誌功能能夠檢索輸入文件並將其加載到我的閃亮會話中。這是一回事嗎? – nFrain
你有'上傳< - eventReactive(...)'。請注意,除非使用'upload()'調用它,否則eventReactive將不會自行運行。 「日誌」工作的原因是因爲你在'renderTable'中調用它。 –