I have been having a problem for two days that the markerClusterOptions() is not working. I can't figure out why . When I run the code without the markerClusterOptions(), it shows the markers, but without a base map. In both cases, the base map is not shown. Any idea what is going on will be much appreciated.
I don't have access to your data, so I am shooting blind.
However, when I consider your leaflet call like this (see below) I don't see any basemap being added. So a display with no basemap is actually the expected behaviour
To elaborate a bit further consider this reproducible example using three NC cities:
library(sf)
library(leaflet)
points <- data.frame(name = c("Raleigh", "Greensboro", "Wilmington"),
x = c(-78.633333, -79.819444, -77.912222),
y = c(35.766667, 36.08, 34.223333)) %>%
st_as_sf(coords = c("x","y"), crs=4326)
# no basemap was specified, and none is shown
leaflet(data = points) %>%
addMarkers()
# a basemap was specified, and so is shown
leaflet(data = points) %>%
addProviderTiles("Stamen.Toner") %>%
addMarkers(clusterOptions = markerClusterOptions())
A shameless plug in: a while back I wrote a long form blog post about using {leaflet} in R, including cluster options. In case you find the topic interesting you can have a look here: Leaflet in R ยท Jindra Lacko
Thank you, @jlacko , for a quick reply. Base maps are working now, but the marker cluster is still not working. I change my code to use fake data using a library called charlatan, and the same problem happens to the script with the fake data.
Thanks for pointing the {charlatan} package out! It will make my reprexes more fun
You are getting there! You just need to assign the marker options argument by name, not by order. Relying on order of arguments places the markerClusterOptions to icon or what not...
I took the liberty to rewrite your code to a somewhat more concise form; the logic stays the same.