Utilizing BeautifyMarker plugin with Leaflet for R

Utilizing the necessary plugins with leaflet() seems to be working just fine. However, when I try to utilize them with renderLeaflet(), they are not working. Does anyone know how to solve this?

Functioning perfectly:

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/"),
                                 script = "leaflet-beautify-marker-icon.min.js",
                                 stylesheet = "leaflet-beautify-marker-icon.min.css"
)

fontawesomePlugin <- htmlDependency("Leaflet.BeautifyMarkerFA", "1.0.9",
                                    src = c(href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/"),
                                    stylesheet = "font-awesome.min.css"
)

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

leaflet() %>% setView(-74.96, 39.77, zoom = 10) %>% addTiles()%>%
  registerPlugin(fontawesomePlugin) %>% 
  registerPlugin(beautifyPlugin) %>%
  onRender(paste0("function(el, x) {
    L.marker([39.77, -74.96] , 
        {icon: L.BeautifyIcon.icon({ icon:'child', iconShape: 'circle' }) }).addTo(this).bindPopup('test');
 }"))

Created on 2020-11-03 by the reprex package (v0.3.0)

Not functioning (from within my server.R file):

    output$map <- renderLeaflet({
        leaflet()%>%addProviderTiles("Esri.WorldGrayCanvas")%>%
            addPolygons(data = shape, color = "black", weight = 1.5, opacity = 1, fill = TRUE, fillOpacity = 0, label = ~NAME, labelOptions = labelOptions(style = list("color" = "black", "font-family" = "serif", "box-shadow" = "3px 3px rgba(0,0,0,0.25)", "font-size" = "15px", "border-color" = "rgba(0,0,0,0.5)")))%>%
            addLegend(position = "topright", colors = c("#483D8B", "#00BFFF"), opacity = 1,labels = c("Externally Provided", "Internally Provided"))%>%
            registerPlugin(fontawesomePlugin) %>% 
            registerPlugin(beautifyPlugin) %>%
            onRender(paste0("function(el, x) {
            L.marker([39.77, -74.96] , 
            {icon: L.BeautifyIcon.icon({ icon:'child', iconShape: 'circle' }) }).addTo(this).bindPopup('test');
                            }"))
    })
#> Error in renderLeaflet({: could not find function "renderLeaflet"

Created on 2020-11-03 by the reprex package (v0.3.0)

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.