Learn R Programming

linkeR (version 0.1.2)

update_leaflet_selection: Update Leaflet Map Selection

Description

update_leaflet_selection updates a Leaflet map component to reflect a new selection state. This function handles both selection and deselection events, applying either custom user-defined click handlers or default behaviors.

Usage

update_leaflet_selection(component_id, selected_id, session, components)

Value

NULL (invisibly). The function is called for its side effects on the Leaflet map.

Arguments

component_id

Character string. The ID of the Leaflet map component to update.

selected_id

Character string or NULL. The ID of the selected item. If NULL, indicates deselection.

session

'shiny' session object. The current 'shiny' session.

components

List. A named list containing component information, where each element contains component configuration including data_reactive, shared_id_column, and config settings.

Details

The function performs the following operations:

  • Validates that the leaflet package is available

  • Checks that required columns (shared_id_column, lng_col, lat_col) exist in the data

  • Clears existing popups on the map

  • For selections: finds the selected data row and applies either custom click handler or default behavior

  • For deselections: delegates to custom handler or performs default cleanup

Required columns in the component data:

  • shared_id_column: Column containing unique identifiers for map features

  • lng_col: Column containing longitude coordinates

  • lat_col: Column containing latitude coordinates