R 在Shining中使用fileInput

R 在Shining中使用fileInput,r,join,shiny,R,Join,Shiny,我有一个闪亮的应用程序,带有数据框输出和上传csv文件的按钮,一旦我上传了csv文件,它必须左键连接(合并)到x数据框: x = data.frame(store=c("store1", "store2", "store35","store1","store3", "store4", "store2"), pos=c("pos1", "pos3", "pos5", "pos9", "pos14", "pos18", "pos24"),

我有一个闪亮的应用程序,带有数据框输出和上传csv文件的按钮,一旦我上传了csv文件,它必须左键连接(合并)到x数据框:

x = data.frame(store=c("store1", "store2", "store35","store1","store3", "store4", "store2"),
               pos=c("pos1", "pos3", "pos5", "pos9", "pos14", "pos18", "pos24"),
               error=c("error1", "error2", "error4", "error3", "error2", "error1", "error3")
)
ui = fluidPage(
  tableOutput("myTable"),
  sidebarLayout(
    sidebarPanel(
      fileInput("file1", "Choose CSV File",
                accept = c(
                  "text/csv",
                  "text/comma-separated-values,text/plain",
                  ".csv")
      ),
      tags$hr(),
      checkboxInput("header", "Header", TRUE)
    ),
    mainPanel(
      tableOutput("contents")
    )
))
server <- shinyServer(function(input, output, session) {
  csv_df <- reactive({
    # input$file1 will be NULL initially. After the user selects
    # and uploads a file, it will be a data frame with 'name',
    # 'size', 'type', and 'datapath' columns. The 'datapath'
    # column will contain the local filenames where the data can
    # be found.
    inFile <- input$file1

    if (is.null(inFile))
      return(NULL)

    read.csv(inFile$datapath, header = input$header)
  })
  req(csv_df())
  output$myTable <- renderTable({
    df <- left_join(x, csv_df(), by = store)
  })

}
)
shinyApp(ui = ui, server = server)

我如何解决这个问题?

应该是
df@MrFlick没有适用于类为“NULL”的对象的“tbl\u vars”的方法。好吧,
左联接
仅在您提供了文件名时才起作用。你什么时候收到新的错误?可能您需要
req(csv_df())
以便只有在您实际提供数据时,联接才会运行。@MrFlick更改了它(也有疑问),但仍然错误:警告:在.getReactiveEnvironment()中出错$currentContext:如果没有活动的反应上下文,则不允许执行操作。(您试图执行的操作只能从反应式表达式或观察者内部执行。).getReactiveEnvironment()$currentContext()中出错:如果没有活动的反应式上下文,则不允许执行操作。(您试图做一些只能在反应式表达式或观察者内部完成的事情。)
req(csv_df())
需要在
renderable
output$myTable中
no applicable method for 'tbl_vars' applied to an object of class "c('reactiveExpr', 'reactive')"