Skip to content

Commit 3d49fbc

Browse files
authored
Add 'plotly_selecting' to acceptable 'on' events (#1280)
1 parent 4642714 commit 3d49fbc

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

NEWS.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## New features
44

55
* `ggplotly()` now supports the `{ggalluvial}` package. (#2061, thanks @moutikabdessabour)
6+
* `highlight()` now supports `on="plotly_selecting"`, enabling client-side linked brushing via mouse click+drag (no mouse-up event required, as with `on="plotly_selected"`). (#1280)
67

78
## Bug fixes
89

R/highlight.R

+2-1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ highlight <- function(p, on = "plotly_click", off,
130130
if (missing(off)) {
131131
off_default <- switch(
132132
on %||% "",
133+
plotly_selecting = ,
133134
plotly_selected = "plotly_deselect",
134135
plotly_click = "plotly_doubleclick",
135136
plotly_hover = "plotly_doubleclick"
@@ -148,7 +149,7 @@ highlight <- function(p, on = "plotly_click", off,
148149
# main (non-plotly.js) spec passed along to HTMLwidgets.renderValue()
149150
p$x$highlight <- list(
150151
# NULL may be used to disable on/off events
151-
on = if (!is.null(on)) match.arg(on, paste0("plotly_", c("click", "hover", "selected"))),
152+
on = if (!is.null(on)) match.arg(on, paste0("plotly_", c("click", "hover", "selected", "selecting"))),
152153
off = if (is.default(off)) off else if (!is.null(off)) match.arg(off, off_options),
153154
persistent = persistent,
154155
dynamic = dynamic,

R/utils.R

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

demo/crosstalk-highlight-intro.R

+2-3
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,14 @@ layout(p, title = "Click on a marker to highlight that patient")
2727
# "plotly_selected", which corresponds to click and drag mouse events.
2828
p %>%
2929
layout(title = "Click and drag to select patient") %>%
30-
highlight("plotly_selected")
31-
30+
highlight("plotly_selecting")
3231

3332
# Plotly provides two types of drag modes that will trigger a "plotly_selected"
3433
# event: "lasso" and "select". You can change the dragmode interactively via
3534
# the modebar and/or set the default dragmode via `layout()`.
3635
p %>%
3736
layout(title = "Click and drag to select patient", dragmode = "lasso") %>%
38-
highlight("plotly_selected")
37+
highlight("plotly_selecting")
3938

4039
# The first argument of `highlight()`, `on`, sets the interaction type used
4140
# trigger a "highlight selection". The second argument, `off`, sets the

0 commit comments

Comments
 (0)