Connects the chart to a Crosstalk SharedData object so that brush selections propagate to other linked widgets.
Usage
setLinked(
myIO,
shared_data,
mode = "both",
filter = FALSE,
key = NULL,
group = NULL,
cursor = FALSE,
cursorAxis = "x"
)Arguments
- myIO
an htmlwidget object created by the
myIO()functiona
crosstalk::SharedDataobject- mode
"source","target", or"both"(default)- filter
if
TRUE, Crosstalk filter operations hide non-matching points. DefaultFALSE(dim only).- key
Optional character vector of row keys. When supplied, overrides the keys extracted from
shared_data. Useful when the SharedData keys do not match the column used for cross-chart matching.- group
Optional character string. When supplied, overrides the Crosstalk group name from
shared_data, allowing manual control over which widgets share selections.- cursor
Logical. When
TRUE, a hover in any linked chart draws a synchronized crosshair on every sibling chart in the same group. DefaultFALSE.- cursorAxis
Character. Which axis to sync:
"x"(default),"y", or"xy". Only"x"is active in v1.2.
Details
Selections travel on the Crosstalk key space, so a myIO chart matches
rows against sibling widgets (DT, plotly, leaflet) by
the same keys they use. The keys are matched to the chart's rows by
position, which requires the data passed to addIoLayer() to be
shared_data$data() in its original row order. If a layer's row
count does not match the number of keys – for example after re-filtering
the frame, or after updateMyIOData() replaced the rows – the
chart falls back to matching within its own widget only, rather than
pairing keys with the wrong rows.
See also
linkCharts for group-identifier linking that does
not require Crosstalk (e.g. static R Markdown / Quarto HTML).
Examples
if (interactive() && requireNamespace("crosstalk", quietly = TRUE)) {
shared <- crosstalk::SharedData$new(mtcars, key = ~rownames(mtcars))
myIO() |>
addIoLayer(
type = "point", label = "scatter",
data = shared$data(), mapping = list(x_var = "wt", y_var = "mpg")
) |>
setLinked(shared)
}
