Layers control in this map work well:
library(leaflet)
mini_quakes <- head(quakes, 10)
mini_quakes$stations <- as.character(mini_quakes$stations)
leaflet(mini_quakes) %>% addTiles() %>%
addMarkers(group = ~stations, # clusterOptions = markerClusterOptions()
) %>%
addLayersControl(overlayGroups = mini_quakes$stations)
However, activating clusterOptions (by uncommenting # clusterOptions = markerClusterOptions()
) prevents layers control to work adequately.
How can addLayersControl
and clusterOptions
work together?
I think the issue is that you aren't defining stations as a single overlay layer, this changing it to a single group name fixes the issue.