R Googleway-在Shiny中关闭图例

时间:2018-08-30 12:02:10

标签: r shiny googleway

如何通过googleway动态“关闭”图例?这是从googleway vignette改编而成的代码(此示例是基于滑块从以前的版本更新的,希望与该问题更相关)

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)

左图在开始时关闭了图例。中间图片是在单击“填充多边形”之后。右图是取消选中“填充多边形”之后的图–您可以看到图例没有消失。 enter image description here

0 个答案:

没有答案