tuimap-shiny: Shiny bindings for tuimap

Description Usage Arguments Examples

Description

Output and render functions for using tuimaps within Shiny applications and interactive Rmd documents.

Usage

1
2
3
tuimapOutput(outputId, width = "100%", height = "400px")

renderTuimap(expr, env = parent.frame(), quoted = FALSE)

Arguments

outputId

output variable to read from

width, height

Must be a valid CSS unit (like '100%', '400px', 'auto') or a number, which will be coerced to a string and have 'px' appended.

expr

An expression that generates a tuimaps

env

The environment in which to evaluate expr.

quoted

Is expr a quoted expression (with quote())? This is useful if you want to save an expression in a variable.

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
41
42
43
44
45
46
47
48
49
50
51
if (interactive()) {

  library(shiny)
  library(rnaturalearth)
  library(dplyr)
  library(tuichartr)

  # Retrieve world map
  world <- ne_countries(returnclass = "sf") %>%
    filter(continent != "Antarctica")

  ui <- fluidPage(
    tags$h2("Include tuimap in Shiny"),
    fluidRow(
      column(
        width = 3,
        actionButton(
          inputId = "refresh",
          label = "Refresh data"
        )
      ),
      column(
        width = 9,
        tuimapOutput(outputId = "my_map")
      )
    )
  )

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

    output$my_map <- renderTuimap({

      input$refresh

      # add a random numeric variable
      world$random <- sample(1:100, nrow(world), TRUE)

      # draw map
      tuimap() %>%
        add_map_data(
          data = world,
          mapping = aes(code = adm0_a3, label = name, value = random)
        ) %>%
        tui_chart(title = "World map (minus Antarctica)")

    })

  }

  shinyApp(ui, server)
}

dreamRs/tuichartr documentation built on Aug. 8, 2020, 9:58 a.m.