I have a map in my shiny App.
I try to filters the markers on my map by a column of my dataframe.
My Data :
remorque time.stamp lat long geolocalisation maintenance temperature appairage
1 21/11/2017 10:36 48.86272 2.2875920 OnMouv noir
2 21/11/2017 10:36 43.60776 1.4421606 StartMouv rouge
3 21/11/2017 10:36 46.58619 0.3388710 OnMouv rouge
4 21/11/2017 10:36 45.76695 3.0556216 Life orange
5 21/11/2017 10:36 45.14555 1.4751652 EndMouv rouge
6 21/11/2017 10:36 46.81157 1.6936336 Life orange
7 21/11/2017 10:36 47.36223 0.6751146 alerte rouge
8 21/11/2017 10:36 47.36032 1.7441244 StartMouv
9 21/11/2017 10:36 48.85333 1.8215332 StartMouv
10 21/11/2017 10:36 48.84429 1.7913208 alerte
11 21/11/2017 10:36 48.81356 1.6759643 EndMouv
In ui.R I add :
selectInput("geolocalisation", "Géolocalisation :",
choice = list("Tous" = "tous",
"OnMouv" = "OnMouv",
"StartMouv" = "StartMouv",
"EndMouv" = "EndMouv",
"Life" = "Life",
"Perte ou Vol" = "alerte"))
And in server.R I did :
output$map <- renderLeaflet({
# Use leaflet() here, and only include aspects of the map that
# won't need to change dynamically (at least, not unless the
# entire map is being torn down and recreated).
leaflet() %>%
addTiles()
})
zerg <-reactive({
test<-ifelse(input$geolocalisation=="OnMouv", return(data_moment[data_moment$geolocalisation=="OnMouv",]),
ifelse(input$geolocalisation=="StartMouv", return(data_moment[data_moment$geolocalisation=="StartMouv",]),
ifelse(input$geolocalisation=="EndMouv", return(data_moment[data_moment$geolocalisation=="EndMouv",]),
ifelse(input$geolocalisation=="Life", return(data_moment[data_moment$geolocalisation=="Life",]),
ifelse(input$geolocalisation=="alerte", return(data_moment[data_moment$geolocalisation=="alerte",]),
return(data_moment))))))
return(test)
})
observe({
dataset<- zerg()
leafletProxy("map", data = dataset) %>%
clearMarkers() %>%
addMarkers(~long, ~lat,clusterOptions = markerClusterOptions(), icon = load_icons(dataset),
popup= ~paste("<h4><font color='#2B547E'><b>Remorque : </font></b>",remorque,"</h4><h4><font color='#2B547E'>Latitude : </font>",lat,"</h4><h4><font color='#2B547E'>Longitude : </font>",long,"</h4>"),
label = ~paste("Remorque : ",remorque,"::: Latitude : ",lat,"::: Longitude : ",long))
})
When I lauch the app, All the markers are displayed (that's good). And when I make a selection, it adds markers, not selecting markers. Just adding new ones which are duplicates.
Do you know why ?
leafletProxy
the map is being updated each time withaddMarkers
, thus new markers on top of old. If you want to strip off the old markers each time the data is updated, just add aremoveMarkers
call before you calladdMarkers
– NateclearMarkers()
is doing ? – celianouError in evalAll: argument "layerId" is missing, with no default
. I think I am not adding it at the right place. – celianouError in eval: argument "expr" is missing, with no default
– celianou