Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signal when leafletProxy is done rendering on the client side #926

Open
daattali opened this issue Jul 27, 2024 · 0 comments
Open

Signal when leafletProxy is done rendering on the client side #926

daattali opened this issue Jul 27, 2024 · 0 comments

Comments

@daattali
Copy link

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, I don't think there's 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. I would like to have some signal or callback when the rendering is complete. Even just triggering shiny's outputinvalidated javascript event would be a step in the right direction.

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant