Skip to contents

Gives traces of a figure the keys of a crosstalk::SharedData, so that selecting their points selects the same rows in other views of the crosstalk group (and the reverse). This happens by itself for px_*() functions given a SharedData as data_frame, and for add_<trace>() traces whose formula properties are evaluated in a SharedData (piped into go_figure() or given as data); use this for other traces. See highlight() for how selections are made and shown.

Usage

set_crosstalk_keys(fig, key, group = NULL, traces = NULL, simple = FALSE)

Arguments

fig

A go_figure().

key

A crosstalk::SharedData, whose row keys give the keys of the points, in the same order as the trace's data; or the keys (a vector with one per point), or a list with the keys of each trace in traces.

group

The crosstalk group. Default: the SharedData's group.

traces

Indices of the traces to link (default: all).

simple

Whether each trace as a whole stands for all its keys (e.g. a line or a fitted curve, which can't be split into points); selecting the trace selects them all, and it is highlighted when all are selected.

Value

fig, linked.

Examples

sd <- crosstalk::SharedData$new(px_data_iris())
iris <- sd$origData()
go_figure() |>
  add_scatter(x = iris$sepal_width, y = iris$sepal_length, mode = "markers") |>
  set_crosstalk_keys(sd) |>
  highlight(on = "plotly_selected")