【问题标题】:R shiny csv or excel upload optionR闪亮的csv或excel上传选项
【发布时间】:2017-02-28 04:14:23
【问题描述】:

我要求用户可以选择上传 .csv/.txt 或 .xlsx 格式的文件。

我正在使用 xlsx 包,并在我的 UI 上提供了一个单选按钮,例如

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 也无法读取我的文件,该选项 1 之前在没有单选按钮和 if 条件的情况下工作。我无法调试,因为调试器会立即运行代码块。

有人可以帮忙吗?

谢谢,

马诺伊阿格拉瓦尔

【问题讨论】:

    标签: r excel csv xlsx shinydashboard


    【解决方案1】:

    啊...我只是在 if 条件中缺少“”,所以它应该是

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-06
      • 2018-06-20
      • 2019-09-27
      • 1970-01-01
      • 2015-10-14
      • 2014-02-23
      • 1970-01-01
      相关资源
      最近更新 更多