How can the legend be 'turned off' dynamically with googleway? Here is the code adapted from the googleway vignette (this example is updated from a previous version based on a slider and is hopefully more relevant to this question)
library(googleway)
library(tidyverse)
library(shiny)
ui <- fluidPage(
checkboxInput("check", "Fill polygons"),
google_mapOutput(outputId = "map")
)
server <- function(input, output){
output$map <- renderGoogle_map({
google_map(key = "") %>%
add_polygons(data = melbourne, id = "polygonId", pathId = "pathId",
polyline = "polyline", fill_opacity = 0, fill_colour = "SA2_NAME",
legend = FALSE, update_map_view = FALSE)
})
# observe check box
observe({
show_legend <- input$check
my_fill_opacity <- as.integer(input$check)
if(show_legend){
google_map_update(map_id = "map") %>%
update_polygons(data = melbourne, id = "polygonId",
fill_opacity = 1, fill_colour = "SA2_NAME",
legend = TRUE)
} else {
google_map_update(map_id = "map") %>%
update_polygons(data = melbourne, id = "polygonId",
fill_opacity = 0, fill_colour = "SA2_NAME",
legend = FALSE)
}
})
}
shinyApp(ui, server)
The left picture is with the legend turned off at the start. The middle picture is after clicking "Fill polygons". The right picture is after unchecking "Fill polygons" - you can see the legend does not disappear.