Skip to content

Commit d2ffbb0

Browse files
committed
maintain backwards-compatibility; document priority argument; update news
1 parent 89296a5 commit d2ffbb0

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
* The `orca_serve()` function was added for efficient exporting of many plotly graphs. For examples, see `help(orca_serve)`.
66
* The `orca()` function gains new arguments `more_args` and `...` for finer control over the underlying system commands.
77

8+
9+
* Improved `event_data()` interface:
10+
* The `event` argument of the `event_data()` function now supports the following events: `plotly_selecting`, `plotly_brushed`, `plotly_brushing`, `plotly_restyle`, `plotly_legendclick`, `plotly_legenddoubleclick`, `plotly_clickannotation`, `plotly_afterplot`, `plotly_doubleclick`, `plotly_deselect`, `plotly_unhover`.
11+
* A new `priority` argument. By setting `priority='event'`, the `event` is treated like a true event: any reactive expression using the `event` becomes invalidated (regardless of whether the input values has changed). For an example, see `plotly_example`
12+
813
## IMPROVEMENTS
914

1015
* Upgraded to plotly.js v1.42.5.

R/shiny.R

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ register_plot_events <- function(p) {
8484
#' with the `source` argument in [plot_ly()] (or [ggplotly()]) to respond to
8585
#' events emitted from that specific plot.
8686
#' @param session a shiny session object (the default should almost always be used).
87+
#' @param priority the priority of the corresponding shiny input value.
88+
#' If equal to `"event"`, then [event_data()] always triggers re-execution,
89+
#' instead of re-executing only when the relevant shiny input value changes
90+
#' (the default).
8791
#' @export
8892
#' @seealso [event_register], [event_unregister]
8993
#' @references
@@ -100,10 +104,10 @@ event_data <- function(
100104
"plotly_selected", "plotly_selecting", "plotly_brushed", "plotly_brushing",
101105
"plotly_deselect", "plotly_relayout", "plotly_restyle", "plotly_legendclick",
102106
"plotly_legenddoubleclick", "plotly_clickannotation", "plotly_afterplot"
103-
),
107+
),
104108
source = "A",
105109
session = shiny::getDefaultReactiveDomain(),
106-
priority = c("event", "input")
110+
priority = c("input", "event")
107111
) {
108112
if (is.null(session)) {
109113
stop("No reactive domain detected. This function can only be called \n",
@@ -113,7 +117,7 @@ event_data <- function(
113117
event <- match.arg(event)
114118
# check to see if this event-source-priority combo is registered
115119
eventID <- paste(event, source, sep = "-")
116-
eventIDRegistered <- eventID %in% session$userData[["plotlyShinyEventIDs"]]
120+
eventIDRegistered <- eventID %in% session$userData$plotlyShinyEventIDs
117121
if (!eventIDRegistered) {
118122
stop(
119123
"The '", event, "' event has not been registered for a source ID ",

inst/examples/shiny/event_priority/app.R

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ ui <- fluidPage(
99
server <- function(input, output, session) {
1010

1111
output$p <- renderPlotly({
12-
plot_ly(x = 1:2, y = 1:2, size = I(c(100, 150))) %>%
13-
add_markers() %>%
14-
event_register("plotly_click", "event")
12+
plot_ly(x = 1, y = 1, marker = list(size = 100)) %>%
13+
add_trace(text = "Click me", mode = "markers+text")
1514
})
1615

1716
output$time1 <- renderText({

man/event_data.Rd

Lines changed: 7 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)