update_legend: Update a legend in Shiny

Description Usage Arguments Examples

Description

Update a legend in Shiny

Usage

1
2
update_legend(proxy, title = "", prefix = "", suffix = "",
  d3_format = NULL)

Arguments

proxy

A d3_map_proxy object.

title

Title for the legend.

prefix

A prefix of legend labels.

suffix

A suffix of legend labels.

d3_format

A string passed to d3.format, see https://github.com/d3/d3-format. If used prefix and suffix are ignored.

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
## Not run: 

if (interactive()) {

library(r2d3maps)
library(shiny)

# data about Paris
data("paris")


# app
ui <- fluidPage(
  fluidRow(
    column(
      width = 8, offset = 2,
      tags$h2("Proxy for continuous breaks scale"),
      d3Output(outputId = "mymap"),
      selectInput(
        inputId = "var", label = "Variable:",
        choices = grep(pattern = "AGE", x = names(paris), value = TRUE)
      )
    )
  )
)

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

  output$mymap <- renderD3({
    d3_map(shape = paris) %>%
      add_continuous_gradient(var = "AGE_00", low = "#FEE0D2", high = "#CB181D") %>%
      add_legend(d3_format = ".2s")
  })

  observeEvent(input$var, {
    d3_map_proxy(shinyId = "mymap", data = paris) %>%
      update_continuous_gradient(var = input$var) %>%
      update_legend(title = tolower(gsub(
        pattern = "_", replacement = " ", x = input$var
      )), d3_format = ".1s")
  }, ignoreInit = TRUE)

}

shinyApp(ui, server)

}


## End(Not run)

dreamRs/r2d3maps documentation built on May 25, 2019, 8:17 a.m.