Skip to content

Commit 5299d22

Browse files
committed
filter out enclosing environment during build phase
1 parent e2d9811 commit 5299d22

File tree

2 files changed

+6
-19
lines changed

2 files changed

+6
-19
lines changed

R/plotly.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ plotly_build <- function(l = last_plot()) {
218218
for (i in seq_along(l$data)) {
219219
d <- l$data[[i]]
220220
# if appropriate, evaluate trace arguments in a suitable environment
221-
idx <- names(d) %in% c("args", "env")
222-
if (sum(idx) == 2) {
221+
idx <- names(d) %in% c("args", "env", "enclos")
222+
if (sum(idx) == 3) {
223223
dat <- c(d[!idx], eval(d$args, as.list(d$env), d$enclos))
224224
dat[c("args", "env", "enclos")] <- NULL
225225
# start processing specially named arguments
@@ -275,8 +275,8 @@ plotly_build <- function(l = last_plot()) {
275275
}
276276
for (i in seq_along(l$layout)) {
277277
layout <- l$layout[[i]]
278-
idx <- names(layout) %in% c("args", "env")
279-
x$layout[[i]] <- if (sum(idx) == 2) {
278+
idx <- names(layout) %in% c("args", "env", "enclos")
279+
x$layout[[i]] <- if (sum(idx) == 3) {
280280
c(layout[!idx], eval(layout$args, as.list(layout$env), layout$enclos))
281281
} else {
282282
layout
@@ -287,8 +287,8 @@ plotly_build <- function(l = last_plot()) {
287287
if (!is.null(l$style)) {
288288
for (i in seq_along(l$style)) {
289289
sty <- l$style[[i]]
290-
idx <- names(sty) %in% c("args", "env")
291-
new_sty <- if (sum(idx) == 2) c(sty[!idx], eval(sty$args, as.list(sty$env), sty$enclos)) else sty
290+
idx <- names(sty) %in% c("args", "env", "enclos")
291+
new_sty <- if (sum(idx) == 3) c(sty[!idx], eval(sty$args, as.list(sty$env), sty$enclos)) else sty
292292
for (k in sty$traces) x$data[[k]] <- modifyList(x$data[[k]], new_sty)
293293
}
294294
}

R/plotly_POST.R

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,8 @@ plotly_POST <- function(x) {
3232
kwargs <- x[get_kwargs()]
3333
kwargs <- kwargs[sapply(kwargs, length) > 0]
3434

35-
# class "environment" from $layout$enclos causes
36-
# Error in unclass(x) : cannot unclass an environment
37-
# in jsonlite::toJSON
38-
# (https://github.com/ropensci/plotly/issues/254)
39-
kwargs <- lapply(kwargs, function(i){
40-
if(class(i)=="list") {
41-
i[sapply(i, class) != "environment"]
42-
} else{
43-
i
44-
}
45-
})
46-
4735
# filename & fileopt are keyword arguments required by the API
4836
# (note they can also be specified by the user)
49-
5037
if (!is.null(x$url) || !is.null(kwargs$filename)) kwargs$fileopt <- "overwrite"
5138
if (is.null(kwargs$filename)) {
5239
kwargs$filename <-

0 commit comments

Comments
 (0)