Home > Back-end >  Filter drop down list based on checkboxinput option
Filter drop down list based on checkboxinput option

Time:11-14

my objective is to filter Country options based on the LMIC column value. Where if(population$LMIC == 'YES') I would like the Countries that have 'YES' value to be displayed in the drop down. else(population$LMIC == 'NO') then I would like the Countries that 'NO' value to be displayed in the drop down. Here is my xlsx file

This is currently what I have for my UI.

div(
                                    id = "dashboard",
                                    pickerInput(
                                        inputId = "selectedCountry",
                                        labelMandatory ("Country"), 
                                        choices = population$Country,
                                        multiple = FALSE,
                                        selected = "Czech Republic", #character(0),# 
                                        options = pickerOptions(
                                            actionsBox = TRUE,
                                            title = "Please select a country")
                                    ),
                                    
                                    checkboxInput(inputId = "filterLMIC", label = strong("Filter LMIC"), value = FALSE),

This is currently what I have for my server,

observeEvent(input$filterLMIC,{
      if(filterLMIC == TRUE){
          updatePickerInput(session, inputId='selectedCountry',
                            choices = population$LMIC,
                            choicesOpt = list(
                              if(population$LMIC == 'YES'){
                                disable
                              }
                            )
                        
                            )
        
      }
    })

I'm not sure where to go from here.

CodePudding user response:

Try this

observeEvent(input$filterLMIC,{
   if (input$filterLMIC) value <- 'YES' else value <- 'NO'
   population <- population[population$LMIC == value,]
   updatePickerInput(session, inputId='selectedCountry', choices = population$Country)
})
  • Related