Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d416cea

Browse filesBrowse files
authored
Merge pull request #1539 from ropensci/renderWidgetPrep
Wrap user-supplied expression in evalq(), closes #1528
2 parents d11bb5a + 3867737 commit d416cea
Copy full SHA for d416cea

File tree

1 file changed

+22
-10
lines changed
Filter options

1 file changed

+22
-10
lines changed

‎R/shiny.R

Copy file name to clipboardExpand all lines: R/shiny.R
+22-10
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,21 @@ plotlyOutput <- function(outputId, width = "100%", height = "400px",
3737
#' @rdname plotly-shiny
3838
#' @export
3939
renderPlotly <- function(expr, env = parent.frame(), quoted = FALSE) {
40-
if (!quoted) { expr <- substitute(expr) } # force quoted
41-
# this makes it possible to pass a ggplot2 object to renderPlotly()
42-
# https://github.com/ramnathv/htmlwidgets/issues/166#issuecomment-153000306
43-
expr <- as.call(list(call(":::", quote("plotly"), quote("prepareWidget")), expr))
44-
renderFunc <- shinyRenderWidget(expr, plotlyOutput, env, quoted = TRUE)
40+
if (!quoted) {
41+
quoted <- TRUE
42+
expr <- substitute(expr)
43+
}
44+
# Install the (user-supplied) expression as a function
45+
# This way, if the user-supplied expression contains a return()
46+
# statement, we can capture that return value and pass it along
47+
# to prepareWidget()
48+
# prepareWidget() makes it possible to pass different non-plotly
49+
# objects to renderPlotly() (e.g., ggplot2, promises). It also is used
50+
# to inform event_data about what events have been registered
51+
shiny::installExprFunction(expr, "func", env, quoted)
52+
renderFunc <- shinyRenderWidget(
53+
plotly:::prepareWidget(func()), plotlyOutput, env, quoted
54+
)
4555
# remove 'internal' plotly attributes that are known to cause false
4656
# positive test results in shinytest (snapshotPreprocessOutput was added
4757
# in shiny 1.0.3.9002, but we require >= 1.1)
@@ -57,13 +67,14 @@ renderPlotly <- function(expr, env = parent.frame(), quoted = FALSE) {
5767

5868
# Converts a plot, OR a promise of a plot, to plotly
5969
prepareWidget <- function(x) {
60-
p <- if (promises::is.promising(x)) {
61-
promises::then(x, plotly_build)
70+
if (promises::is.promising(x)) {
71+
promises::then(
72+
promises::then(x, plotly_build),
73+
register_plot_events
74+
)
6275
} else {
63-
plotly_build(x)
76+
register_plot_events(plotly_build(x))
6477
}
65-
register_plot_events(p)
66-
p
6778
}
6879

6980
register_plot_events <- function(p) {
@@ -73,6 +84,7 @@ register_plot_events <- function(p) {
7384
session$userData$plotlyShinyEventIDs,
7485
eventIDs
7586
))
87+
p
7688
}
7789

7890

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.