Create a Link Registry for Shiny Component Coordination
Source:R/registry.R
create_link_registry.Rd
Creates a registry system that manages linked interactions between multiple Shiny components, allowing them to share selection state and coordinate their behavior.
Value
A link_registry object with the following methods:
- register_component(component_id, type, data_reactive, shared_id_column, config)
Register a new component with the registry. Parameters:
component_id: Unique string identifier for the component
type: Component type (e.g., "table", "plot")
data_reactive: Reactive expression returning the component's data
shared_id_column: Name of the column used for linking selections
config: Optional list of component-specific configuration
- clear_all()
Remove all registered components and reset shared state
- set_selection(selected_id, source_component_id)
Programmatically update the selection state
- get_selection()
Get current selection as list with selected_id and source
- get_on_selection_change()
Return the on_selection_change callback function
- get_components()
Get registry components info (for debugging)
- get_shared_state()
Get current shared state (for debugging)
Details
The registry maintains a shared state across all registered components, automatically setting up observers to synchronize selections. When a selection changes in one component, all other registered components are updated to reflect the same selection.
Components are automatically cleaned up when re-registered to prevent memory leaks from orphaned observers.
See also
setup_component_observers
for component observer setup
Examples
if (FALSE) { # \dontrun{
# In your Shiny server function
registry <- create_link_registry(
session = session,
on_selection_change = function(id, data, source, session) {
message("Selection changed to ID: ", id, " from: ", source)
}
)
# Register components
registry$register_component("table1", "table", reactive(my_data), "id")
registry$register_component("plot1", "plot", reactive(my_data), "id")
} # }