Learn R Programming

linkeR (version 0.1.3)

prepare_plotly_linking: Prepare Plotly for Linking

Description

Utility function to automatically add required parameters to a plotly object for reliable linking, regardless of plot structure (single/multiple traces).

Usage

prepare_plotly_linking(plotly_obj, id_column, source)

Value

Modified plotly object with linking parameters added

Arguments

plotly_obj

A plotly object created with plot_ly()

id_column

Character string: name of the ID column in the data

source

Character string: plotly source identifier

Examples

Run this code
# \donttest{
   library(plotly)

  # Sample data
  df <- data.frame(
    id = 1:5,
    value = c(10, 20, 15, 25, 30),
    group = c("A", "A", "B", "B", "C")
  )

  # Create a plotly scatter plot
  p <- plot_ly(
    data = df,
    x = ~value,
    y = ~id,
    color = ~group
  )

  # Prepare for linking (adds customdata and source)
  p <- prepare_plotly_linking(p, "id", "my_plot")

  # Print the plot object (for demonstration)
  print(p)
# }

Run the code above in your browser using DataLab