topogram_proxy_update: Update topogram with proxy

Description Usage Arguments Value Examples

View source: R/shiny.R

Description

Use this in 'shiny' application to update an already generated topogram().

Usage

1
2
3
4
5
6
7
8
9
topogram_proxy_update(
  proxy,
  sfobj,
  value,
  label = "{value}",
  palette = "viridis",
  rescale_to = c(1, 1000),
  n_iteration = 10
)

Arguments

proxy

A topogram_proxy() htmlwidget object or a valid Shiny output ID.

sfobj

An sf object. For the time being, shape must be projected in Mercator (CRS 4326).

value

Variable name to use to distort topology.

label

glue string to be used in tooltip, you can use HTML tags in it.

palette

Name of a color palette, such as "viridis", "Blues", ... Or a function to map data values to colors, see scales::col_numeric().

rescale_to

Rescale value to distort topology to a specified range, use NULL to use values as is.

n_iteration

Number of iterations to run the algorithm for. Higher numbers distorts the areas closer to their associated value, at the cost of performance.

Value

A topogram_proxy htmlwidget object.

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
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.