I'm having an issue with having two mapboxer outputs in a Shiny project, and getting both separate mapboxer_proxy calls to work.
See code below that describes two mapboxer outputs in two separate UI tabs. Both maps display just fine initially. When I run the app, and in the first tab, if I change the selectInput it triggers the mapboxer_proxy call with a set_filter() and fit_bounds(), and it updates the data and zoom into the new data's bounding area. I can continue to use selectInput, and it will continue to update the filter and zoom as expected.
Then if I go to the second tab, and do the same thing, it also does filters and zooms data for the second map. I can continue to do this, and it works just fine.
But if I then subsequently go from tab 2 back to tab 1, the mapboxer_proxy no longer filters or zooms to the bounds on map 1. I can still manually pan/zoom the map. But if I continue to try changing the selectInput, the mapboxer_proxy doesn't filter or zoom.
But, if I go back to tab 2, mapboxer_proxy continues to work for map 2.
Any ideas on why the first mapboxer_proxy stops responding?
Thanks!
ui <- fluidPage(
titlePanel(title = "Test multitab shiny maps"),
navbarPage(title = "Two Maps",
tabPanel("Map1",
selectInput("selectState1",
label = "Select State",
choices = state.name,
selected = "Washington"),
mapboxerOutput("mapbox1")
),
tabPanel("Map2",
selectInput("selectState2",
label = "Select State",
choices = state.name,
selected = "Washington"),
mapboxerOutput("mapbox2")
)
)
)
server <- function(input, output) {
##render map 1----
output$mapbox1 <- renderMapboxer({
mapboxer() %>%
add_layer(style = list(
id = "my_map1",
type = "fill",
source = edmund_source,
"source-layer" = "my_tiles",
paint = list(
"fill-color" = list(
"interpolate",
list("linear"),
list("get", "my_var"),
0,
'#edf8b1',
1,
'#2c7fb8')
),
filter = list("==", "SF", "Washington") # this is initial setting, but changed in proxy when UI selectState changes.
))
})
##update the map1----
observeEvent(input$selectState1, {
print("changed state1")
mapboxer_proxy("mapbox1") %>%
set_filter("my_map1", list("==", "SF", input$selectState1)) %>%
fit_bounds( the_states[the_states$NAME.x == input$selectState1,] ) %>%
update_mapboxer()
})
##render map 2----
output$mapbox2 <- renderMapboxer({
mapboxer() %>%
add_layer(style = list(
id = "my_map2",
type = "fill",
source = edmund_source,
"source-layer" = "my_tiles",
paint = list(
"fill-color" = list(
"interpolate",
list("linear"),
list("get", "my_var"),
0,
'#edf8b1',
1,
'#dc4f58')
),
filter = list("==", "SF", "Washington") # this is initial setting, but changed in proxy when UI selectState changes.
))
})
##update the map2----
observeEvent(input$selectState2, {
print("changed state2")
mapboxer_proxy("mapbox2") %>%
set_filter("my_map2", list("==", "SF", input$selectState2)) %>%
fit_bounds( the_states[the_states$NAME.x == input$selectState2,] ) %>%
update_mapboxer()
})
}
I'm having an issue with having two mapboxer outputs in a Shiny project, and getting both separate mapboxer_proxy calls to work.
See code below that describes two mapboxer outputs in two separate UI tabs. Both maps display just fine initially. When I run the app, and in the first tab, if I change the selectInput it triggers the mapboxer_proxy call with a set_filter() and fit_bounds(), and it updates the data and zoom into the new data's bounding area. I can continue to use selectInput, and it will continue to update the filter and zoom as expected.
Then if I go to the second tab, and do the same thing, it also does filters and zooms data for the second map. I can continue to do this, and it works just fine.
But if I then subsequently go from tab 2 back to tab 1, the mapboxer_proxy no longer filters or zooms to the bounds on map 1. I can still manually pan/zoom the map. But if I continue to try changing the selectInput, the mapboxer_proxy doesn't filter or zoom.
But, if I go back to tab 2, mapboxer_proxy continues to work for map 2.
Any ideas on why the first mapboxer_proxy stops responding?
Thanks!