1

如何使用 googleway 动态“关闭”图例?这是改编自googleway 小插图的代码(此示例是从基于滑块的先前版本更新的,希望与此问题更相关)

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)

左图是图例在开始时关闭的情况。中间的图片是点击“填充多边形”后。右图是取消选中“填充多边形”后 - 您可以看到图例没有消失。 在此处输入图像描述

4

0 回答 0