Skip to content

Commit 1cf9021

Browse files
committed
Support Shiny async/promises based rendering
1 parent b21b740 commit 1cf9021

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

DESCRIPTION

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ Imports:
4343
rlang,
4444
crosstalk,
4545
purrr,
46-
data.table
46+
data.table,
47+
promises
4748
Suggests:
4849
MASS,
4950
maps,
@@ -52,7 +53,7 @@ Suggests:
5253
testthat,
5354
knitr,
5455
devtools,
55-
shiny (>= 0.14),
56+
shiny (>= 1.1.0),
5657
curl,
5758
rmarkdown,
5859
Rserve,

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* The selection (i.e., linked-brushing) mode can now switch from 'transient' to 'persistent' by holding the 'shift' key. It's still possible to _force_ persistent selection by setting `persistent = TRUE` in `highlight()`, but `persistent = FALSE` (the default) is now recommended since it allows one to switch between [persistent/transient selection](https://plotly-book.cpsievert.me/linking-views-without-shiny.html#transient-versus-persistent-selection) in the browser, rather than at the command line.
1313
* The `highlight()` function gains a `debounce` argument for throttling the rate at which `on` events may be fired. This is mainly useful for improving user experience when `highlight(on = "plotly_hover")` and mousing over relevant markers at a rapid rate (see #1277)
1414
* The `animation_button()` function gains a `label` argument, making it easier to control the label of an animation button generated through the `frame` API (see #1205).
15+
* You can now do async rendering of Plotly plots with Shiny, using the [promises](https://rstudio.github.io/promises/) package.
1516

1617
## CHANGES
1718

R/shiny.R

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,19 @@ renderPlotly <- function(expr, env = parent.frame(), quoted = FALSE) {
3838
if (!quoted) { expr <- substitute(expr) } # force quoted
3939
# this makes it possible to pass a ggplot2 object to renderPlotly()
4040
# https://github.com/ramnathv/htmlwidgets/issues/166#issuecomment-153000306
41-
expr <- as.call(list(call("::", quote("plotly"), quote("ggplotly")), expr))
41+
expr <- as.call(list(call(":::", quote("plotly"), quote("prepareWidget")), expr))
4242
shinyRenderWidget(expr, plotlyOutput, env, quoted = TRUE)
4343
}
4444

45+
# Converts a plot, OR a promise of a plot, to plotly
46+
prepareWidget <- function(x) {
47+
if (promises::is.promising(x)) {
48+
promises::then(x, ggplotly)
49+
} else {
50+
ggplotly(x)
51+
}
52+
}
53+
4554

4655
#' Access plotly user input event data in shiny
4756
#'

0 commit comments

Comments
 (0)