@@ -170,7 +170,7 @@ layout <- function(p = last_plot(), ...,
170
170
enclos = parent.frame()
171
171
)
172
172
p <- last_plot(p )
173
- p $ layout <- c(p $ layout , list (layout ))
173
+ p $ layout <- c(p $ layout , list (layout = layout ))
174
174
if (evaluate ) p <- plotly_build(p )
175
175
hash_plot(data , p )
176
176
}
@@ -273,10 +273,12 @@ plotly_build <- function(l = last_plot()) {
273
273
} else if (any(idx )) {
274
274
c(data = c(l $ data , l [idx ]), l [! idx ])
275
275
} else l
276
- # carry over properties, if necessary
276
+ # carry over properties, if necessary (but don't carry over evaluation envir)
277
277
if (length(l $ data ) > 1 && isTRUE(l $ data [[1 ]]$ inherit )) {
278
+ d <- l $ data [[1 ]]
279
+ d <- d [! names(d ) %in% c(" env" , " enclos" )]
278
280
for (i in seq.int(2 , length(l $ data ))) {
279
- l $ data [[i ]] <- modifyList(l $ data [[i ]], l $ data [[ 1 ]] )
281
+ l $ data [[i ]] <- modifyList(l $ data [[i ]], d )
280
282
}
281
283
}
282
284
# 'x' is the same as 'l', but with arguments evaluated
@@ -322,17 +324,10 @@ plotly_build <- function(l = last_plot()) {
322
324
x $ data <- c(x $ data , list (d ))
323
325
}
324
326
}
325
- # layout() tacks on an unnamed list element to potentially pre-existing
326
- # layout(s). Note that ggplotly() will return a named list
327
- # of length n >= 1 (so we need to carefully merge them ).
327
+ # it's possible have nested layouts (e.g., plot_ly() %>% layout() %>% layout())
328
328
nms <- names(l $ layout )
329
- if (! is.null(nms ) && any(idx <- nms %in% " " )) {
330
- # TODO: does this always preserve the correct order to layouts?
331
- # (important since we use modifyList at a later point)
332
- l $ layout <- c(list (l $ layout [! idx ]), l $ layout [idx ])
333
- } else {
334
- l $ layout <- list (l $ layout )
335
- }
329
+ idx <- nms %in% " layout"
330
+ l $ layout <- c(list (l $ layout [! idx ]), setNames(l $ layout [idx ], NULL ))
336
331
for (i in seq_along(l $ layout )) {
337
332
x $ layout [[i ]] <- perform_eval(l $ layout [[i ]])
338
333
}
0 commit comments