1

Does anyone know if it is possible to initialize the filters defined in the selectizeGroupUI with the first value in each of the filters? Something like the "selected" option in the selectInput. Let's say I have the following code:

if (interactive()) {
  
  library(shiny)
  library(shinyWidgets)
  
  data("mpg", package = "ggplot2")
  
  ui <- fluidPage(
    fluidRow(
      column(
        width = 10, offset = 1,
        tags$h3("Filter data with selectize group"),
        panel(
          pickerInput(
            inputId = "car_select",
            choices = unique(mpg$manufacturer),
            options = list(
              `live-search` = TRUE,
              title = "None selected"
            )
          ),
          selectizeGroupUI(
            id = "my-filters",
            params = list(
              manufacturer = list(inputId = "manufacturer", title = "Manufacturer:"),
              model = list(inputId = "model", title = "Model:"),
              trans = list(inputId = "trans", title = "Trans:"),
              class = list(inputId = "class", title = "Class:")
            )
          ),
          status = "primary"
        ),
        DT::dataTableOutput(outputId = "table")
      )
    )
  )
  
  server <- function(input, output, session) {
    
    mpg_filter <- reactive({
      subset(mpg, manufacturer %in% input$car_select)
    })
    
    res_mod <- callModule(
      module = selectizeGroupServer,
      id = "my-filters",
      data = mpg_filter,
      vars = c("manufacturer", "model", "trans", "class")
    )
    
    output$table <- DT::renderDataTable({
      req(res_mod())
      res_mod()
    })
  }
  
  shinyApp(ui, server)
}

If I select "audi" in the pickerInput, is it possible that instantly the filters of "Manufacturer", "Model", "Trans" and "Class" take the value of the first option they have?

I tried to assign a value to the filter with input[["my-filters-model"]] but it shows an error that Can't modify read-only reactive value

ismirsehregal
  • 30,045
  • 5
  • 31
  • 78
DART
  • 11
  • 2

0 Answers0