pickerInput with observeEvent Select All as default

I have a pickerInput with an action box with default/selected to be all selected. This works completely as expected and wanted.

When I combine the pickerInput with observeEvent selected doesn't work and the default is nothing selected. The observeEvent filters the pickerInput list.

The pickerInput is

   pickerInput("SchoolSelect",
                   label = "Select School:",
                   choices = c(ASData %>%
                                 filter(!is.na(School)) %>%
                                 select(School) %>%
                                 unique() %>%
                                 arrange(School)),
                   selected = ASData$School,
                   options = list('actions-box' = TRUE),
                    multiple = TRUE),

And the observeEvent

observeEvent(input$LASelect, {
  updatePickerInput(session,
                           inputId = "SchoolSelect",
                           choices = c(ASData %>%
                                         filter(!is.na(School), LA == input$LASelect, Year == input$YearSelect,
                                                SchoolCount == '1') %>%
                                         select(School) %>%
                                         unique() %>%
                                     arrange(School)))

Can anyone help? I've tried adding in:

                selected = c(ASData %>%
                                      filter(!is.na(School), LA == input$LASelect, Year == input$YearSelect,
                                             SchoolCount == '1') %>%
                                      select(School) %>%
                                      unique() %>%
                                      arrange(School)))

to the observeEvent but this also didn't work

You'll be more likely to get help if you create a simple reprex, as described in https://mastering-shiny.org/action-workflow.html#reprex

In the meantime, you might try pulling our the choices into a separate reactive, so that you can check if it's generating the correct values:

choices <- reactive({
  ASData %>%
  filter(
    !is.na(School), 
    LA == input$LASelect, 
    Year == input$YearSelect, 
    SchoolCount == '1'
  ) %>%
  pull(School) %>%
  unique() %>%
  sort()
})

(You'll notice my code is a bit different from yours, because you were generating a data frame, which is probably not what you want)

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.