Skip to content

Commit 510b617

Browse files
committed
Add 'plotly_selecting' to acceptable 'on' events
1 parent 9e4e5cc commit 510b617

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

R/highlight.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ highlight <- function(p, on = "plotly_click", off,
145145
# main (non-plotly.js) spec passed along to HTMLwidgets.renderValue()
146146
p$x$highlight <- list(
147147
# NULL may be used to disable on/off events
148-
on = if (!is.null(on)) match.arg(on, paste0("plotly_", c("click", "hover", "selected"))),
148+
on = if (!is.null(on)) match.arg(on, paste0("plotly_", c("click", "hover", "selected", "selecting"))),
149149
off = if (is.default(off)) off else if (!is.null(off)) match.arg(off, off_options),
150150
persistent = persistent,
151151
dynamic = dynamic,

R/utils.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ supply_highlight_attrs <- function(p) {
402402
# add HTML dependencies, set a sensible dragmode default, & throw messages
403403
if (hasKeys) {
404404
p$x$layout$dragmode <- p$x$layout$dragmode %|D|%
405-
default(switch(p$x$highlight$on %||% "", plotly_selected = "select") %||% "zoom")
405+
default(switch(p$x$highlight$on %||% "", plotly_selected = "select", plotly_selecting = "select") %||% "zoom")
406406
if (is.default(p$x$highlight$off)) {
407407
message(
408408
sprintf(

demo/crosstalk-highlight-intro.R

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ sd <- SharedData$new(df, ~patient)
1616
p <- plot_ly(sd, x = ~visit, y = ~perc, color = I("black"),
1717
text = ~paste("Patient:", patient)) %>%
1818
group_by(patient) %>%
19-
add_trace(mode = "markers+lines") %>%
20-
highlight("plotly_selected")
19+
add_trace(mode = "markers+lines")
20+
21+
highlight(p, "plotly_selecting", color = "red")
2122

2223
# Since crosstalk's SharedData object was supplied to plot_ly() with a key of
2324
# patient, it knows to highlight any lines/markers matching the selected patient(s).
2425
# By default, the "on trigger" is "plotly_click", but we've changed that to
25-
# "plotly_selected", which corresponds to click and drag mouse events.
26+
# "plotly_selecting", which corresponds to click and drag mouse events.
2627
# Plotly provides two types of drag modes that will trigger a "plotly_selected"
2728
# event: "lasso" and "select". You can change the dragmode interactively via
2829
# the modebar and/or set the default dragmode via `layout()`.

0 commit comments

Comments
 (0)