Learn R Programming

linkeR (version 0.1.3)

apply_default_plotly_behavior: Apply Default Plotly Behavior for Selection Highlighting

Description

Implements selection highlighting using plotly's native selectedpoints mechanism. This leverages plotly's built-in selection system which works consistently across all chart types without hardcoded styling values.

Usage

apply_default_plotly_behavior(plot_proxy, selected_row, session, component_id)

Value

NULL (invisible). Function is called for side effects only.

Arguments

plot_proxy

plotlyProxy object for the target plot.

selected_row

Data frame row containing the selected data point, or NULL for deselection.

session

Shiny session object for the current user session.

component_id

Character string. ID of the plotly component for reference.

Details

This function uses plotly's native selection capabilities by:

  • Finding points using key or customdata across all traces

  • Applying plotly's built-in selectedpoints styling

  • Using plotly's default selected/unselected appearance

  • Working generically across all plot types and trace structures

For native plotly selection highlighting to work, your Shiny UI must include a custom JavaScript message handler:


tags$script(HTML("
  Shiny.addCustomMessageHandler('eval', function(code) {
    try {
      eval(code);
    } catch(e) {
      console.error('JavaScript execution error:', e);
    }
  });
"))

This enables linkeR to send selection updates to plotly charts for visual feedback.

The selection highlighting follows plotly's native behavior and appearance, ensuring consistency with user expectations and plotly's design system.