update_choropleth: Dynamically add bubbles

Description Usage Arguments Examples

Description

Dynamically add bubbles using Shiny.

Usage

1
update_choropleth(proxy, locations, color, reset = FALSE, ...)

Arguments

proxy

a proxy as returned by datamapsProxy.

locations

column containing location names as iso3c.

color

column containing color of each location.

reset

reset previous changes to default color from datamaps.

...

any other variable to use for tooltip.

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
## Not run: 
library(shiny)

ui <- fluidPage(
  selectInput(
    "countrySelect",
    "Select Country",
    choices = c("USA", "FRA", "CHN", "RUS", "COG", "DZA", "BRA", "IND")
  ),
  sliderInput(
    "value",
    "Value",
    min = 1,
    max = 10,
    value = 5
  ),
  actionButton("update", "Update"),
  datamapsOutput("map")
)

server <- function(input, output){

  data <- data.frame(name = c("USA", "FRA", "CHN", "RUS", "COG", "DZA", "BRA", "IND", "ALG", "AFG"),
                     color = 1:10)

 updated_data <- reactive({
   data.frame(name = input$countrySelect, value = input$value)
 })

  output$map <- renderDatamaps({
    data %>%
      datamaps() %>%
      add_choropleth(name, color)
  })

  observeEvent(input$update, {
    datamapsProxy("map") %>%
      add_data(updated_data()) %>% # pass updated data
      update_choropleth(name, value, TRUE) # update
  })
}

shinyApp(ui, server)

## End(Not run)

datamaps documentation built on May 2, 2019, 1:09 p.m.