Shiny R:Excel 文件输入到数据表输出(数据表中有输入)
Shiny R: Excel file input to datatable output (with inputs in the datatable)
我对 Shiny 比较陌生,我想 table 包含来自文件输入的数据,其中第一列的值可以从某些选项中选择。这适用于不是来自文件输入的数据。
在 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 <- as.data.frame(data3)
但是我总是收到错误消息:
Error in as.data.frame.default(data3): cannot coerce class ‘c("reactiveExpr", "reactive", "function")’ to a data.frame
我能做什么?
当您尝试使用它时,您是否需要将 data3
称为 data3()
,因为它是一个反应性数据集?
我对 Shiny 比较陌生,我想 table 包含来自文件输入的数据,其中第一列的值可以从某些选项中选择。这适用于不是来自文件输入的数据。
在 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 <- as.data.frame(data3) 但是我总是收到错误消息:
Error in as.data.frame.default(data3): cannot coerce class ‘c("reactiveExpr", "reactive", "function")’ to a data.frame
我能做什么?
当您尝试使用它时,您是否需要将 data3
称为 data3()
,因为它是一个反应性数据集?