JRomeo
JRomeo

Reputation: 181

R/Shiny: Populate CheckBox Group Dynamically Using Headers From Uploaded File

I'm trying to build a page using R Shiny that has:

I'd like to use these as follows:

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.

Upvotes: 0

Views: 338

Answers (1)

Ronak Shah
Ronak Shah

Reputation: 388982

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.

Upvotes: 1

Related Questions