How to force background refresh of leaflet map on multitab dashboard

I have created a multi-tab dashboard in flexdashboard with a shiny runtime. Each tab includes a leaflet map panel. On initial load, they all work fine, but when navigating between tabs the leaflet map gets re-centered.

For example, on initial load the map looks like this:

After navigating to tab 2 (which also has a map of the same geography), and returning to tab 1, the map on tab 1 that we saw above loads like this:

I'd like to build into the code a background refresh of the leaflet map when navigating to a tab. Does anyone know how to do this?

Here is the code that creates the leaflet map:

renderLeaflet({
  leaflet() |> 
  addProviderTiles('CartoDB') |>
    addPolygons(data = show_polygon(),
               weight = 2, smooth = 0.5, opacity = 0.25, fillOpacity = 0,
               label = ~htmlEscape(filter_name)) |>
    addMarkers(data = show_pins() |> 
                      lat = ~CENTROID_LATITUDE,
                      lng = ~CENTROID_LONGITUDE,
                      icon = ~icon[STATUS], 
                      popup = ~ name_label,
                      options = markerOptions(opacity = 0.8)) |>
    addCircleMarkers(data = show_circle_data(),
             lat = ~Latitude,
             lng = ~Longitude,
             radius = ~(radius * 3),
             fillOpacity = 0.8,
             popup = ~label,
             color = ~radius_pal(radius)
             )
})

See similar issue here, with no resolution: How to refresh/reset map? · Issue #755 · rstudio/leaflet · GitHub

Someone mentioned a similar issue and possible solution here: Version 0.6.* bug. Multiple Leaflet maps will no longer display correctly when alternating back and forth. · Issue #432 · rstudio/flexdashboard (github.com)

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