Obtaining Leaflet Cluster information from R Shiny

Viewed 435

I am using Leaflet as a mapping and marker-clustering service for my RShiny App. As R's leaflet package hasn't got the marker clustering functionality (https://github.com/Leaflet/Leaflet.markercluster), i had to import it as an additional Addon:

   registerPlugin <- function(map, plugin) {
map$dependencies <- c(map$dependencies, list(plugin))
map
}

clusterPlugin<-htmlDependency("Leaflet.markercluster", "1.0.0",
                            src = c(href = "https://github.com/Leaflet/Leaflet.markercluster/tree/master/build"),
                            script = "build.js"
)

output$map <- renderLeaflet({
(leaflet() %>% setView(lng = 10.23, lat = 50.18, zoom = 5)) %>% 
  addTiles()%>%
  setView(10.23, 50.18, zoom = 5) %>%
  registerPlugin(clusterPlugin) %>%
  addMarkers(alldata$Longitude, alldata$Latitude, clusterOptions = markerClusterOptions())
})    

Leaflet Marker Cluster Example

My question is, how do I extract information such as the number and the names of the markers in the highlighted cluster? How can I communicate with JavaScript by using R without having a dedicated package for that? I was thinking about using a right click on the cluster to view possible options.

0 Answers
Related