Learn R Programming

datamaps (version 0.0.3)

update_arcs: Dynamically update arcs

Description

Dynamically update arcs with Shiny.

Usage

update_arcs(proxy, origin.lon, origin.lat, destination.lon, destination.lat,
  ...)

update_arcs_name(proxy, origin, destination, ...)

Arguments

proxy

a proxy as returned by datamapsProxy.

origin.lon

origin coordinates.

origin.lat

origin coordinates.

destination.lon

destination coordinates.

destination.lat

destination coordinates.

...

any other arguments to use as options.

origin

edges.

destination

edges.

Examples

Run this code
# NOT RUN {
library(shiny)

ui <- fluidPage(

  textInput(
    "from",
    "Origin",
    value = "USA"
  ),
  textInput(
    "to",
    "Destination",
    value = "RUS"
  ),
  actionButton(
    "submit",
    "Draw arc"
  ),
  datamapsOutput("map")
)

server <- function(input, output){

  arc <- reactive({
    data.frame(from = input$from, to = input$to)
  })

 output$map <- renderDatamaps({
   datamaps()
 })

 observeEvent(input$submit, {
   datamapsProxy("map") %>%
     add_data(arc()) %>%
     update_arcs_name(from, to)
 })

}

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

Run the code above in your browser using DataLab