【问题标题】:Shiny R: Excel file input to datatable output (with inputs in the datatable)Shiny R:Excel 文件输入到数据表输出(在数据表中输入)
【发布时间】:2021-05-08 23:39:39
【问题描述】:

我对 Shiny 比较陌生,我希望有一个表格,其中包含来自文件输入的数据,其中第一列中的值可以从某些选项中选择。这适用于不是来自文件输入的数据。

在 UI 部分,我采用文件输入和输出:

fileinput('file1','Data')
DT::dataTableOutput("ruless")

然后以下工作:

 values <- reactiveValues(data = NULL)
 values$data <- as.data.frame(
    cbind(c("a", "d", "b", "c", "e", "f"),
          c(1463, 159, 54, 52, 52, 220),
          c(0.7315, 0.0795, 0.027, 0.026, 0.026, 0.11)
    )
  )
  
  shinyInput = function(FUN, len, id, ...) {
    inputs = character(len)
    for (i in seq_len(len)) {
      inputs[i] = as.character(FUN(paste0(id, i), label = NULL, choices = c("Cylinders" = "cyl",
                                                                  "Transmission" = "am")))
    }
    inputs
  }
  
  output$ruless <- DT::renderDataTable({
    datatable(
      data.frame(Choose=shinyInput(selectInput,nrow(values$data),"cbox_"), values$data)
      )
    )
  })

但现在我想对来自文件输入的数据做同样的事情。 我尝试了以下方法:

data3 <- reactive({
    inFile <- input$file1
    if (is.null(inFile)) { return(NULL) }    
    dataFile <- read_excel(inFile$datapath,sheet=1)
    return(dataFile)
  })

然后使用 data3 代替 values$data 或尝试 values$data

Error in as.data.frame.default(data3): cannot coerce class ‘c("reactiveExpr", "reactive", "function")’ to a data.frame

我能做什么?

【问题讨论】:

    标签: r shiny datatable reactive readxl


    【解决方案1】:

    仅仅是因为它是一个响应式数据集,所以您在尝试使用它时需要将data3 称为data3() 吗?

    【讨论】:

      猜你喜欢
      • 2023-04-01
      • 2017-03-16
      • 1970-01-01
      • 1970-01-01
      • 2019-02-05
      • 2021-10-27
      • 1970-01-01
      • 1970-01-01
      • 2020-01-29
      相关资源
      最近更新 更多