I am trying to get this set of markers from the mrt
dataset to appear at a certain zoom level. I'm new to leaflet in r and would like some advice on this.
I tried using an if statement
that should have the markers appear at a certain zoom level. But it doe not work.
Here's an example of the mrt
data
stn_code mrt_station lat lon
1 NS1 Jurong East 1.333131 103.7421
2 NS2 Bukit Batok 1.349064 103.7496
3 NS3 Bukit Gombak 1.359037 103.7518
4 NS4 Choa Chu Kang 1.385385 103.7443
5 NS5 Yew Tee 1.397329 103.7475
6 NS7 Kranji 1.425227 103.7620
Here's the portion of code that renders the leaflet map.
output$mymap <- renderLeaflet({
leaflet(data=df()) %>%
addTiles() %>%
addPolygons(data=adm, weight = 3, fillColor = "white", popup=popup)%>%
addMarkers(clusterOptions = markerClusterOptions(),
label = paste(df()$address,',',df()$town))%>%
if (input$map_zoom>6){
addMarkers(data=mrt,lat = ~lat,lng = ~lon,label=mrt$mrt_station,icon = mrticon)
}
})
Thanks!