I'm trying to create an app where people can upload a CSV and then interact with the data. The specific issues is I'm failing to pass the column headers from the file that is read in to the selectInput function.
If you comment out the last few lines for the observe function the app works fine. Have tried a number of options, using reactive instead of renderTable etc. There are some similar questions around addressing changing the select input but none that I could see from a file read in. Seems the lack of anything in 'contents' to begin with is the issue?
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()))
})
}
)
Test CSV
Col1,Col2,Col3
2,3,4
5,6,7