R shiny orgranize grouped choices into multiple selectInput boxes (and user selects two for a scatter plot)

276 views Asked by At

I have a lot of variables in a dataset that fall into separate categories. If I add a list to the choices argument in selectInput, it is too cumbersome to scroll through the choices for each category. Is there any way I can organize the categories across multiple selectInput boxes? The idea is that the user would be able to select from 1 of the 4 selectInput boxes for both the x-axis and the y-axis to generate a scatter plot. Or maybe there's a better way to address this problem? I should note that the data is ultra wide (thousands of columns), so my categories are selecting from column names.

1

There are 1 answers

0
Stéphane Laurent On BEST ANSWER

Your question is not clear to me but maybe selectizeInput with the optgroup_columns plugin is a solution:

library(shiny)

ui <- fluidPage(
  br(),
  selectizeInput(
    "std", "Select the standard",
    choices = list(
      "C" = list("c89", "c99", "c11"),
      "C++" = list("c++03", "c++11", "c++14", "c++17", "c++20")
    ),
    options = list(
      plugins = list("optgroup_columns")
    )
  )  
)

server <- function(input, output, session) {}

shinyApp(ui, server)

enter image description here

The group headers are not nice, you can style them with CSS, e.g.

.selectize-dropdown .optgroup>.optgroup-header {
  font-size: 15px;
  font-weight: bold;
  font-style: italic;
  color: black;
}