The Leaflet JS mapping library has lots of plugins available. The Leaflet package for R provides direct support for some, but far from all, of these plugins, by providing R functions for invoking the plugins.
If you as an R user find yourself wanting to use a Leaflet plugin that isn't directly supported in the R package, you can use the technique shown here to load the plugin yourself and invoke it using JS code.
This is really helpful information. We are trying implement the 'leaflet-measure' plugin but it simply does not render properly (renders without any icons being displayed). This post seems like a promising solution, but on trial and error, it fails to load any plugins that are of type leaflet-control. Dunno if this is the correct place to post, but I would really appreciate some help to rectify the issue.
Here's my code to use the leaflet-control type plugins using this method.
`library(leaflet)
library(htmltools)
library(htmlwidgets)
LeafletMeasure <- htmlDependency("leaflet-measure","3.1.0",
src = c(href="https://github.com/ljigis/leaflet-measure/src"),
script="leaflet-measure.js",
stylesheet = "https://github.com/ljigis/leaflet-measure/scss/leaflet-measure.scss")
registerPlugin <- function(map, plugin) {
map$dependencies <- c(map$dependencies, list(plugin))
map
}
leaflet() %>% addTiles() %>%
setView(lng = 12, lat = 50, zoom = 4) %>%
registerPlugin(LeafletMeasure) %>%
onRender("
function(el, x) {
measureControl.addTo(this);}")`
The plugin has a scss that is in a different folder from the standard src folder. I have tried referencing the file through the Github repository as well as local copy.