add_click: Retrieve click in Shiny

Description Usage Arguments Examples

Description

Retrieve click in Shiny

Usage

1
add_click(map, inputId, layerId = NULL, action = "click")

Arguments

map

A r2d3map htmlwidget object.

inputId

The input slot that will be used to access the value.

layerId

Name of a variable present in data to filter results returned, if NULL (default) all columns are returned.

action

What triggers input value server-side, click or dblclick.

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
## Not run: 
library( r2d3maps )
library( r2d3 )
library( rnaturalearth )
library( shiny )

france <- ne_states(country = "france", returnclass = "sf")
france <- france[france$type_en %in% "Metropolitan department", ]

if (interactive()) {
  ui <- fluidPage(

    fluidRow(
      column(
        offset = 2, width = 8,
        tags$h2("r2d3maps Shiny example"),
        fluidRow(
          column(
            width = 6,
            d3Output(outputId = "map")
          ),
          column(
            width = 6,
            verbatimTextOutput(outputId = "res_click")
          )
        )
      )
    )

  )

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

    output$map <- renderD3({
      d3_map(shape = france) %>%
        add_tooltip() %>%
        add_click(
          inputId = "myclick",
          layerId = "name", # return only name,
          # NULL to get all data
          action = "dblclick" # on double click,
          # use "click" for simple click
        )
    })

    output$res_click <- renderPrint({
      str(input$myclick, max.level = 2)
    })
  }

  shinyApp(ui, server)
}

## End(Not run)

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