具有空表的R renderDataTable

具有空表的R renderDataTable,r,shiny,R,Shiny,如果数据存在,那么最好的方法是仅以文本形式呈现数据表?现在,我得到了以下错误,因为我告诉shiny渲染一个数据表,即使它是空的 Warning in file(file, "rt") : cannot open file '\': No such file or directory Warning: Error in file: cannot open the connection 我的代码是这样分割的,一旦用户选择csv文件,我就读取数据。用户选择

如果数据存在,那么最好的方法是仅以文本形式呈现数据表?现在,我得到了以下错误,因为我告诉shiny渲染一个数据表,即使它是空的

    Warning in file(file, "rt") :
    cannot open file '\': No such file or directory
    Warning: Error in file: cannot open the connection
我的代码是这样分割的,一旦用户选择csv文件,我就读取数据。用户选择csv文件后,错误消失,一切正常。如何告诉Shiny在选择有效文件之前不要显示数据表

filedata <- reactive({
  if (is.null(input$file_selector)){
    # User has not uploaded a file yet
    return(NULL)
  } else {
  read.csv(paste0(parseDirPath(c(home = 'C:\\Users\\Ruben'), file_dir()),'\\',input$file_selector),skip=1)}
})

output$filetable <- renderDataTable({
  filedata()
})
filedata请使用
req()
,如下所示

filedata <- reactive({
  req(input$file_selector)
  read.csv(paste0(parseDirPath(c(home = 'C:\\Users\\Ruben'), file_dir()),'\\',input$file_selector),skip=1)
})
filedata您可以使用req()函数,这将检查该文件是否存在,然后它将转到处理代码

filedata <- reactive({
  file <-input$file_selector
  req(file)
  read.csv(paste0(parseDirPath(c(home = 'C:\\Users\\Ruben'), file_dir()),'\\',file),skip=1)}
})
filedata