Rshiny的CSV或Excel上传选项

我有一个要求给用户上传一个.csv / .txt或.xlsx格式文件的选项。

我正在使用xlsx软件包,并在我的用户界面上提供了一个单选button,例如

ui <- dashboardPage( dashboardHeader(title = "SKU Health Check App"), dashboardSidebar( width = 350, radioButtons( "fileType_Input", label = h4("Choose File type"), choices = list(".csv/txt" = 1, ".xlsx" = 2), selected = 1, inline = TRUE ), fileInput( 'file1', h4('Upload Items List'), accept = c( 'text/csv', 'text/comma-separated-values,text/plain', '.csv', '.xlsx' ) ), 

并处理服务器中的选项

 server <- function(input, output, session) { # Get the upload file get_item_list <- reactive({ inFile <- input$file1 if (is.null(inFile)) { return(NULL) } if (input$fileType_Input == 1) { read.csv(inFile$datapath, header = TRUE, stringsAsFactors = FALSE) } else { read.xlsx(inFile$datapath, header = TRUE,sheetIndex = 1, stringsAsFactors = FALSE) } }) 

但我得到错误,因为我的文件没有被读取,即使选项1更早工作,没有单选button,如果条件。 我无法debugging,因为debugging器一次运行代码块。

有人可以帮忙吗?

谢谢,

Manoj Agrawal

呃…我只是在if条件中失踪了,所以应该是这样

 if (input$fileType_Input == "1") { read.csv(inFile$datapath,