mapboxer-shiny: Shiny bindings for mapboxer

Description Usage Arguments Examples

Description

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

Usage

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

renderMapboxer(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 mapboxer

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
52
53
54
55
56
57
58
59
library(shiny)
library(mapboxer)

LAYER_ID <- "mvc"

view <- basicPage(
  h1("mapboxer"),
  sliderInput(
    "slider",
    "Number of persons injured",
    min = 0,
    max = max(motor_vehicle_collisions_nyc$injured),
    step = 1,
    value = 0
  ),
  checkboxInput("hide", "Hide layer"),
  mapboxerOutput("map"),
  htmlOutput("datetime")
)

server <- function(input, output) {
  output$map <- renderMapboxer({
      as_mapbox_source(motor_vehicle_collisions_nyc) %>%
      mapboxer(
        center = c(-73.9165, 40.7114),
        zoom = 10,
        style = basemap_raster_style(stamen_raster_tiles())
      ) %>%
      add_circle_layer(
        circle_color = "black",
        popup = "Number of persons injured {{injured}}",
        id = LAYER_ID
      ) %>%
      add_mouse_position_control(
        "Lng: {{lng}}</br>Lat: {{lat}}",
        css_text = "text-align: left; width: 180px;"
      ) %>%
      add_navigation_control(pos = "top-left")
  })

  observeEvent(input$slider, {
    mapboxer_proxy("map") %>%
      set_filter(LAYER_ID, list("==", "injured", input$slider)) %>%
      update_mapboxer()
  })

  observeEvent(input$hide, {
    mapboxer_proxy("map") %>%
      set_layout_property(LAYER_ID, "visibility", !input$hide) %>%
      update_mapboxer()
  })

  output$datetime <- renderText({
    props <- input$map_onclick$props
    sprintf("<p>%s %s</p>", props$date, props$time)
  })
}

if (interactive()) shinyApp(view, server)

crazycapivara/mapboxer documentation built on Nov. 13, 2021, 3:22 a.m.