Learn R Programming

linkeR (version 0.1.2)

register_leaflet: Register a Leaflet Component

Description

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
)

Value

No return value, called for side effects.

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

shared_id_column

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

Run this code
# \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())
# }

Run the code above in your browser using DataLab