examples/proxy-update.R

library(topogram)
library(shiny)

ui <- fluidPage(
  tags$h2("Update topogram with proxy"),
  radioButtons(
    inputId = "new_value",
    label = "Select a variable:",
    choices = names(world)[3:7],
    inline = TRUE
  ),
  topogramOutput(outputId = "ID", height = "800px")
)

server <- function(input, output, session) {

  # Initialize the topogram (non reactive)
  output$ID <- renderTopogram({
    topogram(
      sfobj = world,
      value = "pop_est", 
      label = "{name} : {value}"
    ) %>% 
      topogram_legend(title = "Population")
  })

  # Update with proxy
  observeEvent(input$new_value, {
    topogram_proxy_update(
      "ID", world, 
      value = input$new_value,
      label = "{name} : {value}"
    ) %>% 
      topogram_legend(title = input$new_value)
  }, ignoreInit = TRUE)

}

if (interactive())
  shinyApp(ui, server)
dreamRs/topogRam documentation built on Dec. 16, 2021, 6:47 p.m.