2

I have built a Shiny app that displays info for public school districts and schools. The starting sidebar simply offers for the user to pick from polygons (School Districts, Counties and Zipcodes) or points (schools, colleges, businesses). Once "School districts" is selected, the sidebar shows a SelectInput with a list of school districts. Once a district is selected, ANOTHER conditional panel shows a SelectInput with a list of campuses. Below is the code for the two conditional panels. Notice the "choices" for the "camp" panel is empty.

    conditionalPanel(condition = "output.districts",
                     selectizeInput(inputId = "schdist", label = "Choose a District:", choices = district_options, 
                                    multiple = FALSE, options = list(placeholder = 'Select one', 
                                                                     onInitialize = I('function() { this.setValue(""); }')))),

    conditionalPanel(condition= "output.districts", 
                     conditionalPanel(condition = "input.schdist != ''",
                     selectizeInput(inputId = "camp", label = "Campuses:",
                                    choices = "",
                                    multiple = F,
                                    options = list(placeholder = 'Select one',
                                                   onInitialize = I('function() { this.setValue(""); }'))))        ),

Here are the reactive variable and observe event that update the "camp" choices:

  school_choices <- reactive({
    dist <- district_data[district_data@data$NAME == input$schdist, ]
    choices <- campus_data[(campus_data$DISTNAME %in% dist@data$NAME), ]
    choices <- choices$CAMPNAME
    return(sort(choices))
  })

  observe({
    updateSelectInput(session, "camp", choices = school_choices())})

This code all works just fine. BUT I also have click events in my Leaflet map that update different SelectInputs (which then trigger other features of the app to display etc.) Currently in my app, from the start of the app, a user can select "ISD campuses" to display on the Leaflet map. When a user clicks on one of these markers, I want to update the "schdist" input AND the "camp" input. The code I have now works to update the "schdist" and show the correct choices for the "camp" input, but it will not update the "camp" input as selected = click$id. Here is how it's written currently:

  observeEvent(input$baseMap_marker_click, {
    click <- input$baseMap_marker_click      
    if(click$id %in% campus_data$CAMPNAME) {
      df = campus_data[campus_data$CAMPNAME == click$id,]
      updateSelectizeInput(session, "polygons", selected="Independent School Districts")
      updateSelectizeInput(session, "schdist", selected= df$DISTNAME)
      updateSelectizeInput(session, "camp", selected=click$id)
}
})

I've also tried this:

if(click$id %in% campus_data$CAMPNAME) {
      df = campus_data[campus_data$CAMPNAME == click$id,]
      updateSelectizeInput(session, "polygons", selected="Independent School Districts")
      updateSelectizeInput(session, "schdist", selected= df$DISTNAME)
        if(is.null(input$camp)){
          updateSelectizeInput(session, "camp", selected=click$id)
        }

But it behaves the same way.

So is it possible for me to updateSelectInput that is reactive to another updateSelectInput?

Lara Haase
  • 45
  • 5
  • This issue is still present, but I realized that if the user clicks on the same marker a SECOND time, then the behavior is appropriate, as the `input$camp` is updated (since the first click updated `input$schdist`). Is it possible to have it update all 3 `selectizeInput`s on the first click? – Lara Haase Mar 26 '19 at 15:29

0 Answers0