update_legend: Dynamically update legend

Description Usage Arguments Examples

View source: R/proxies.R

Description

Dynamically update legend using Shiny

Usage

1

Arguments

proxy

a proxy as returned by datamapsProxy.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
## 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)

## End(Not run)

JohnCoene/datamaps documentation built on May 17, 2018, 12:17 p.m.