Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

143
Vistas
Using Leaflet.Sync in OnRender JavaScript code for Leaflet visual in R

I've been trying to create a Leaflet map visual in R that syncs two maps (two maps are shown next to each other and when you move/zoom on one map the other map moves along with that). This works fine using the R leafsync package, see this picture. However, the end goal is to use this R Visual in a PowerBI report and the leafsync package is not supported by PowerBI. Therefore, I would like to use the Javascript Leaflet.Sync package in a OnRender function when creating the R visual. Below is the code I have so far, where map1 and map2 are earlier crated Leaflet map visuals in R:

# A function that takes a plugin htmlDependency object and adds
# it to the map. This ensures that however or whenever the map
# gets rendered, the plugin will be loaded into the browser.
registerPlugin <- function(map, plugin) {
  map$dependencies <- c(map$dependencies, list(plugin))
  map
}

# This tells htmlwidgets about our plugin name, version, and where to find the script
syncPlugin <- htmlDependency("Leaflet.Sync", "0.2.4",
                             src = c(href = "https://cdn.jsdelivr.net/gh/jieter/Leaflet.Sync/"),
                             script = list("L.Map.Sync.js"))

map2 = map2 %>%
# Register Sync Plugin on this map instance
registerPlugin(syncPlugin) %>%
# Add your custom JS logic here. The `this` keyword refers to the Leaflet (JS) map object.
onRender("function(el, x, data) {
  this.sync(data);
  data.sync(this);
}", data=map1)
map2

This is currently not working (the result I get is the original map2 visual that is unable to move or zoom, the map1 visual is nowhere to be seen), however I'm not sure why and thus I have a couple of questions:

  • I'm not sure if the syncPlugin is correctly registered, how would I check if that's the case?
  • I'm not sure if the Leaflet map visual map1 is correctly passed to the OnRender function, any suggestions on how I check if that's the case?
  • Is what I'm trying to do even possible? Can I call this sync function while rendering a map object or should this be done after rendering the map objects? If so, any suggestions on how to do this, because I cannot use the JavaScript Leaflet.Sync package in my R script except for in this OnRender function right?

Many thanks in advance for any help provided! :)

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda