【发布时间】:2015-09-03 13:24:25
【问题描述】:
我正在尝试创建一个应用程序,人们可以在其中上传 CSV,然后与数据进行交互。 具体问题是我未能将读入的文件中的列标题传递给 selectInput 函数。
如果您注释掉观察功能的最后几行,则应用可以正常工作。尝试了许多选项,使用响应式而不是 renderTable 等。关于解决更改选择输入的问题有一些类似的问题,但我无法从读入的文件中看到。似乎“内容”中缺少任何内容问题?
require(shiny)
runApp(
list(
ui = fluidPage(
sidebarPanel(fileInput('file1', 'Choose CSV File',
accept=c('text/csv',
'text/comma-separated-values,text/plain',
'.csv')),
selectInput("inSelect", "Select something", choices = "Pending Upload")
),
mainPanel(
tableOutput("contents"))
),
server = function(input, output) {
output$contents <- renderTable({
inFile <- input$file1
if (is.null(inFile))
return(NULL)
read.csv(inFile$datapath)
})
observe({
updateSelectInput(session, "inSelect", choices = names(contents()))
})
}
)
测试 CSV
Col1,Col2,Col3
2,3,4
5,6,7
【问题讨论】: