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_choropleth: Dynamically add bubbles

Description

Dynamically add bubbles using Shiny.

Usage

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

Run this code
# 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)
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab