bwc
bwc

Reputation: 1115

Alternatives to checkboxGroupInput for multiple parameter selection in Shiny?

I've got a shiny app that is used to analyze 30 years of climate data. I'd like to have the user be able to select as many years as they'd like within the 30 years to plot on top of each other. Obviously, checkboxGroupInput could be used, however, displaying 30 checkboxes on screen is not visually pleasing.

Are there alternatives (such as drop down "multi-selections") available?

Upvotes: 0

Views: 1293

Answers (2)

shosaco
shosaco

Reputation: 6155

The plain alternative would be selectInput with multiple = TRUE. If you don't mind using an external package, bwc's answer comes in handy. See the following demo:

library(shiny)
library(shinyWidgets)

ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(selectInput("choiceSelectize", "Choose one or more:", choices = 1:10, multiple = TRUE),
                 pickerInput("choicePicker", "Choose one or more:", choices = 1:10, multiple = TRUE)),
    mainPanel("Plain shiny Select Input:", verbatimTextOutput("outSelectize"),
              "ShinyWidgets Picker Input:", verbatimTextOutput("outPicker"))
  )
)

server <- function(input, output) {

  output$outSelectize <- renderPrint({
    input$choiceSelectize
  })

  output$outPicker <- renderPrint({
    input$choicePicker
  })
}

shinyApp(ui, server)

enter image description here

Upvotes: 3

bwc
bwc

Reputation: 1115

Looks like the pickerInput() or checkboxGroupButtons from the shinyWidgets package will do the trick.

Upvotes: 0

Related Questions