Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

145
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda