Skip to content

Commit

Permalink
Add 'plotly_selecting' to acceptable 'on' events
Browse files Browse the repository at this point in the history
  • Loading branch information
cpsievert committed Nov 2, 2021
1 parent 4642714 commit ec1dec9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
3 changes: 2 additions & 1 deletion R/highlight.R
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ highlight <- function(p, on = "plotly_click", off,
if (missing(off)) {
off_default <- switch(
on %||% "",
plotly_selecting = ,
plotly_selected = "plotly_deselect",
plotly_click = "plotly_doubleclick",
plotly_hover = "plotly_doubleclick"
Expand All @@ -148,7 +149,7 @@ highlight <- function(p, on = "plotly_click", off,
# main (non-plotly.js) spec passed along to HTMLwidgets.renderValue()
p$x$highlight <- list(
# NULL may be used to disable on/off events
on = if (!is.null(on)) match.arg(on, paste0("plotly_", c("click", "hover", "selected"))),
on = if (!is.null(on)) match.arg(on, paste0("plotly_", c("click", "hover", "selected", "selecting"))),
off = if (is.default(off)) off else if (!is.null(off)) match.arg(off, off_options),
persistent = persistent,
dynamic = dynamic,
Expand Down
2 changes: 1 addition & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ supply_highlight_attrs <- function(p) {
# add HTML dependencies, set a sensible dragmode default, & throw messages
if (hasKeys) {
p$x$layout$dragmode <- p$x$layout$dragmode %|D|%
default(switch(p$x$highlight$on %||% "", plotly_selected = "select") %||% "zoom")
default(switch(p$x$highlight$on %||% "", plotly_selected = "select", plotly_selecting = "select") %||% "zoom")
if (is.default(p$x$highlight$off)) {
message(
sprintf(
Expand Down
5 changes: 2 additions & 3 deletions demo/crosstalk-highlight-intro.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,14 @@ layout(p, title = "Click on a marker to highlight that patient")
# "plotly_selected", which corresponds to click and drag mouse events.
p %>%
layout(title = "Click and drag to select patient") %>%
highlight("plotly_selected")

highlight("plotly_selecting")

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

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

0 comments on commit ec1dec9

Please sign in to comment.