Dynamically add bubbles using Shiny.

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

# 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)
# }