0

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
    What exactly is your question? What is the problem you are facing? Also, could you create a reproducible example? – Annet May 04 '21 at 06:36
  • The map does not load, I think it is due to the use of the if. i need help with if – Francisco1988 May 04 '21 at 10:48
  • It could be the if, or for all we know it could be that you don’t call the object. Hence the need for a reproducible example. – Annet May 04 '21 at 11:55
  • I added a link with the photo of the map when it was executed ... Note that the map does not load I suppose it is for the reason of the if ... – Francisco1988 May 04 '21 at 14:10
  • A reproducible example actually contains data and code that runs on it own. – Annet May 04 '21 at 17:35

1 Answers1

0

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)
  }
})
Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225