register_leaflet registers a Leaflet map for linking with other components.
Usage
register_leaflet(
session,
registry,
leaflet_output_id,
data_reactive,
shared_id_column,
lng_col = "longitude",
lat_col = "latitude",
highlight_zoom = 12,
click_handler = NULL
)Arguments
- session
'shiny' session object. The session from the module where the DT is used. This could be global session in non-modular apps.
- registry
A link registry created by
create_link_registry()- leaflet_output_id
Character string: the outputId of your leafletOutput
- data_reactive
Reactive expression returning the data frame for the map
Character string: name of the ID column
- lng_col
Character string: name of longitude column (default: "longitude")
- lat_col
Character string: name of latitude column (default: "latitude")
- highlight_zoom
Numeric: zoom level when highlighting (default: 12)
- click_handler
Optional function: custom click handler for row selection, must have args (map_proxy, selected_data, session), overrides all default behavior
Examples
# \donttest{
# Create a mock session for the example
session <- shiny::MockShinySession$new()
# Create a registry
registry <- create_link_registry(session)
# Sample reactive data
my_data <- shiny::reactive({
data.frame(
id = 1:5,
name = c("A", "B", "C", "D", "E"),
longitude = -111.9 + runif(5, -0.1, 0.1),
latitude = 40.7 + runif(5, -0.1, 0.1)
)
})
# Register a leaflet component
register_leaflet(session, registry, "my_map", my_data, "id")
# Verify registration
print(registry$get_components())
#> $`mock-session-my_map`
#> $`mock-session-my_map`$type
#> [1] "leaflet"
#>
#> $`mock-session-my_map`$shared_id_column
#> [1] "id"
#>
#> $`mock-session-my_map`$config
#> $`mock-session-my_map`$config$lng_col
#> [1] "longitude"
#>
#> $`mock-session-my_map`$config$lat_col
#> [1] "latitude"
#>
#> $`mock-session-my_map`$config$highlight_zoom
#> [1] 12
#>
#> $`mock-session-my_map`$config$highlight_icon
#> $`mock-session-my_map`$config$highlight_icon$icon
#> [1] "star"
#>
#> $`mock-session-my_map`$config$highlight_icon$library
#> [1] "glyphicon"
#>
#> $`mock-session-my_map`$config$highlight_icon$markerColor
#> [1] "red"
#>
#> $`mock-session-my_map`$config$highlight_icon$iconColor
#> [1] "#FFFFFF"
#>
#> $`mock-session-my_map`$config$highlight_icon$spin
#> [1] FALSE
#>
#> $`mock-session-my_map`$config$highlight_icon$squareMarker
#> [1] FALSE
#>
#> $`mock-session-my_map`$config$highlight_icon$iconRotate
#> [1] 0
#>
#> $`mock-session-my_map`$config$highlight_icon$font
#> [1] "monospace"
#>
#>
#> $`mock-session-my_map`$config$original_data_reactive
#> reactive({
#> data.frame(id = 1:5, name = c("A", "B", "C", "D", "E"), longitude = -111.9 +
#> runif(5, -0.1, 0.1), latitude = 40.7 + runif(5, -0.1,
#> 0.1))
#> })
#>
#> $`mock-session-my_map`$config$click_handler
#> NULL
#>
#>
#>
# }