How to know when `leafletProxy` finishes rendering an updated map?

With a plain leaflet map, we can use htmlwidgets::onRender() in order to perform an action when the map finishes rendering.

When using leafletProxy() to update a map, is there any way to know when the rendering of the update finished?

Here's an example shiny app, when you press the button it adds polygons. How can I get a callback when the rendering on the client side is complete?

library(shiny)
library(leaflet)
library(sf)

polys <- st_sf(
  geometry = st_sfc(
    st_polygon(list(rbind(
      c(-101.744384765625, 39.32155002466662),
      c(-101.5521240234375, 39.330048552942415),
      c(-101.40380859375, 39.330048552942415),
      c(-101.33239746093749, 39.364032338047984),
      c(-101.041259765625, 39.36827914916011),
      c(-100.975341796875, 39.30454987014581),
      c(-101.0399169921875, 39.24501680713314),
      c(-101.243896484375, 39.16414104768742),
      c(-101.455078125, 39.11125631228113),
      c(-101.737060546875, 39.13006024213511),
      c(-101.77825927734375, 39.16839962520706),
      c(-101.734619140625, 39.254884981213734),
      c(-101.744384765625, 39.32155002466662)
    )))
  )
)

ui <- fluidPage(
  leafletOutput("map"),
  actionButton("go", "go")
)

server <- function(input, output, session) {
  output$map <- renderLeaflet({
    leaflet() %>% 
      addTiles() %>%
      setView(-101, 39, 8)
  })
  
  observeEvent(input$go, {
    leafletProxy("map") %>%
      addPolygons(data = polys)
  })
}

shinyApp(ui, server)

The only thing i could find that goes in that direction is map.leafletr.hasRendered where map is declared based on the "id" which is provided in the leafletProxy list. But as you said it is hard to get it working without a JS hack and having some onRender like function would be nice.

Here a SO crosspost can be found.

This topic was automatically closed 90 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.