Description Usage Arguments Examples
Retrieve click in Shiny
1 |
map |
A |
inputId |
The |
layerId |
Name of a variable present in data to filter results returned,
if |
action |
What triggers input value server-side, |
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.