2

我建立了一个闪亮的应用程序,显示公立学区和学校的信息。起始侧边栏只是让用户从多边形(学区、县和邮政编码)或点(学校、学院、企业)中进行选择。选择“学区”后,侧边栏会显示带有学区列表的 SelectInput。选择一个学区后,另一个条件面板会显示一个带有校区列表的 SelectInput。下面是两个条件面板的代码。注意“camp”面板的“choices”是空的。

    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(""); }'))))        ),

以下是更新“营地”选择的反应变量和观察事件:

  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())})

这段代码一切正常。但我的传单地图中也有点击事件,更新不同的 SelectInputs(然后触发应用程序的其他功能显示等)。目前在我的应用程序中,从应用程序开始,用户可以选择“ISD 校园”来显示在传单地图上。当用户单击这些标记之一时,我想更新“schdist”输入和“camp”输入。我现在的代码可以更新“schdist”并显示“camp”输入的正确选择,但它不会将“camp”输入更新为 selected = click$id。这是它目前的编写方式:

  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)
}
})

我也试过这个:

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)
        }

但它的行为方式相同。

那么我是否可以更新对另一个 updateSelectInput 有反应的 updateSelectInput?

4

0 回答 0