全部在闪亮的选择输入中

All in shiny selectinput

enter image description here我有一张闪亮的地图,我需要在其中过滤掉原住民和非原住民。但我还需要过滤掉所有原住民和非原住民。我正在使用选择输入。

filtered <- reactive({
      filter(places_df,INDIGENA == input$INDIGENA)

if(input$INDIGENA =='ALL')
places_df

    })

    output$MapPlot1 <- renderLeaflet({
      
        leaflet(data =  filtered())%>% 
        setView(-51.127166, -4.299999, 10)%>%  
        addTiles()%>%
        addMarkers(popup = paste0(places_df$ID.GRUPO.FAMILIAR, "</br>", places_df$LOCALIDADES))
    
    })
    
    
    observe(
      leafletProxy("MapPlot1", data = filtered ())%>%  
        clearMarkers()%>%  
        addMarkers(popup = paste0(places_df$ID.GRUPO.FAMILIAR, "</br>", places_df$LOCALIDADES))
      )
    

与函数类似,反应导体 returns 它主体的最后一条语句。如果input$INDIGENA不等于'ALL',那么语句

  if(input$INDIGENA == 'ALL'){
    places_df
  }

计算为 NULL

尝试:

filtered <- reactive({
  if(input$INDIGENA == 'ALL'){
    places_df
  }else{
    filter(places_df,INDIGENA == input$INDIGENA)
  }
})