diff --git a/inst/examples/DT-crosstalk/plotly-persist.R b/inst/examples/DT-crosstalk/plotly-persist.R new file mode 100644 index 00000000..a74e23e1 --- /dev/null +++ b/inst/examples/DT-crosstalk/plotly-persist.R @@ -0,0 +1,15 @@ +library(plotly) +library(crosstalk) +library(DT) + +m <- SharedData$new(mtcars) +bscols( + plot_ly(m, x = ~wt, y = ~mpg) %>% + add_markers() %>% + config(displayModeBar = FALSE) %>% + layout( + title = "Hold shift while clicking \n markers for persistent selection", + margin = list(t = 60) + ), + datatable(m) +) diff --git a/inst/htmlwidgets/datatables.js b/inst/htmlwidgets/datatables.js index 1d451db6..b8bdedb5 100644 --- a/inst/htmlwidgets/datatables.js +++ b/inst/htmlwidgets/datatables.js @@ -320,7 +320,12 @@ HTMLWidgets.widget({ } if (e.sender !== instance.ctselectHandle && e.value && e.value.length) { - $table[0].ctselect = keysToMatches(e.value); + var ctOpts = crosstalk.var("plotlyCrosstalkOpts").get() || {}; + if (ctOpts.persistent === true) { + $table[0].ctselect = [].concat($table[0].ctselect, keysToMatches(e.value)); + } else { + $table[0].ctselect = keysToMatches(e.value); + } table.draw(); } else { if ($table[0].ctselect) {