【发布时间】: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