I'm trying to build a page using R Shiny that has:
A File Widget for uploading CSV files
A Checkbox Group component
I'd like to use these as follows:
- Upon uploading a valid CSV file, populate the CheckBox group whose checkboxes are all the headers from the CSV file, all checked by default
I've tried various forms of observe() and observeEvent() so far, but have had no success in getting this even close. Any suggestions you may have would be great.
CodePudding user response:
You may try checkboxGroupInput
.
library(shiny)
ui <- fluidPage(
fileInput('file', 'Upload csv file'),
uiOutput('dropdown')
)
server <- function(input, output) {
data <- reactive({
req(input$file)
read.csv(input$file$datapath)
})
output$dropdown <- renderUI({
req(data())
checkboxGroupInput('cols', 'Select Column', names(data()),
names(data()), inline = TRUE)
})
}
shinyApp(ui, server)
You can set inline = FALSE
if you want to arrange them vertically.