Free Access Week-  Data Engineering + BI
Data engineering and BI courses are free!
Free AI Access Week from June 2-8

datamaps (version 0.0.3)

update_legend: Dynamically update legend

Description

Dynamically update legend using Shiny

Usage

update_legend(proxy)

Arguments

proxy

a proxy as returned by datamapsProxy.

Examples

Run this code
# NOT RUN {
library(shiny)

ui <- fluidPage(
  actionButton(
    "show",
    "Show legend"
  ),
  datamapsOutput("map")
)

server <- function(input, output){
  states <- data.frame(st = c("AR", "NY", "CA", "IL", "CO", "MT", "TX"),
                       val = c(10, 5, 3, 8, 6, 7, 2))

  output$map <- renderDatamaps({
    states %>%
      datamaps(scope = "usa", default = "lightgray") %>%
      add_choropleth(st, val)
  })

  observeEvent(input$update, {
    datamapsProxy("map") %>%
      update_legend() # update
  })
}

shinyApp(ui, server)
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab