Using BeautifyMarker with Leaflet for R
nash1119 opened this issue · comments
I am trying to use the BeautifyMarker plugin with Leaflet for R by loading the plugin and utilizing the onRender() function (technique described here https://gist.github.com/jcheng5/c084a59717f18e947a17955007dc5f92). I am unable to load the plugin successfully. I think my assignments in htmlDependency() might be the issue, but I can't seem to figure this out. I would appreciate any help!
library(leaflet)
library(htmltools)
library(htmlwidgets)
library(fontawesome)
beautifyPlugin <- htmlDependency("Leaflet.BeautifyMarker", "1.0.9",
src = c(href = "https://cdn.jsdelivr.net/npm/beautifymarker@1.0.9/package.json"),
script = "https://cdn.jsdelivr.net/npm/beautifymarker@1.0.9/leaflet-beautify-marker-icon.min.js",
stylesheet = "https://cdn.jsdelivr.net/npm/beautifymarker@1.0.9/leaflet-beautify-marker-icon.min.css"
)
registerPlugin <- function(map, plugin) {
map$dependencies <- c(map$dependencies, list(plugin))
map
}
leaflet() %>% setView(-122.23, 37.75, zoom = 10)%>%
addTiles()%>%
registerPlugin(beautifyPlugin) %>%
onRender("function(el, x) {
L.marker([37.77, -122.40] ,
{icon: L.BeautifyIcon.icon()
}).addTo(this).bindPopup('test');
}")
Created on 2020-09-23 by the reprex package (v0.3.0)