All in shiny selectinput

113 Views Asked by At

enter image description hereI have a map in shiny where I need to filter out indigenous and non-indigenous people. But I also need to filter out all indigenous and non-indigenous people. I am using selectinput.

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

There are 1 best solutions below

0
On BEST ANSWER

Similarly to a function, a reactive conductor returns the last statement of its body. If input$INDIGENA is not equal to 'ALL', then the statement

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

evaluates to NULL.

Try:

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