title: Expand/Collapse Shiny selectInput function
body: <p>I would like to find a resource that would allow my Shiny selectInput function to expand/collapse based on the category headings that I have created. I have searched through some bootstrap resources, but am not yet successful. Please forgive my minimal working example, I acknowledge that there may be more efficient ways to provide a MWE. Thanks for any advice you can offer. </p>
  
  <pre><code>library(shiny)
  library(tidyverse)
  #create a quick dataset to plot
  schools &lt;-  as.data.frame(table(
      c('Adams', 'Van Buren', 'Clinton', 'Douglas', 'Edwards', 
                'Franklin', 'Grant', 'Harrison', 'Ignatius', 'Justice', 
                'Kellogg', 'Lincoln'), 
      dnn = list("school")))
  
  enrollment &lt;- as.data.frame(table(
      c(300, 305, 265, 400, 500, 450, 475, 900, 800, 850, 1200, 1500), 
      dnn = list("enrollment")))
  
  schoolsDataframe &lt;- schools %&gt;% 
      bind_cols(enrollment) %&gt;% 
      select(school, enrollment)
  
  #define data elements for selectInput choices argument
  elem &lt;- c('Adams', 'Van Buren', 'Clinton', 'Douglas')
  mid &lt;- c('Edwards', 'Franklin', 'Grant')
  high &lt;- c('Harrison', 'Ignatius', 'Justice')
  multi &lt;- c('Kellogg', 'Lincoln')
  
  # Define UI 
  ui &lt;- fluidPage(
      tags$style(".optgroup-header { color: #FFFFFF !important; background: #000000 !important; }"),
      # Application title
      titlePanel("Expandable selectInput"),
  
      # Sidebar with a select input
      sidebarLayout(
          sidebarPanel(
              selectInput(inputId = 'schoolsInput',
                          label = 'Select a school',
                          choices = list('Elementary' = elem, 
                                         'Middle' = mid, 
                                         'High' = high, 
                                         'Multi-level' = multi), 
                          selectize = TRUE)
          ),
  
          # Show a plot 
          mainPanel(
             plotOutput("myPlot")
          )
      )
  )
  
  # Define server logic required to draw a plot
  server &lt;- function(input, output) {
  
      output$myPlot &lt;- renderPlot({
          #filter the data based on selectInput
  schoolsDataframe &lt;- schoolsDataframe %&gt;% 
      filter(school == input$schoolsInput)
          # draw the plot
  ggplot(data = schoolsDataframe, 
         mapping = aes(x = school, 
                       y = enrollment))+
      geom_col()
      })
  }
  
  # Run the application 
  shinyApp(ui = ui, server = server)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/BJ193.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BJ193.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/5Ubxb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5Ubxb.png" alt="enter image description here"></a></p>