Skip to content

Commit ab93d5a

Browse files
committed
subplot now accepts a list of plots
1 parent a978fbc commit ab93d5a

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

R/subplots.R

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@
3232
subplot <- function(..., nrows = 1, widths = NULL, heights = NULL, margin = 0.02,
3333
shareX = FALSE, shareY = FALSE, titleX = shareX,
3434
titleY = shareY, which_layout = "merge") {
35+
# are the dots a list of plotly objects?
36+
dotz <- list(...)
37+
if (length(dotz) == 1 && is.list(dotz) && !is.plotly(dotz)) {
38+
dotz <- dotz[[1]]
39+
}
3540
# build each plot
36-
plotz <- lapply(list(...), plotly_build)
41+
plotz <- lapply(dotz, plotly_build)
3742
# ensure "axis-reference" trace attributes are properly formatted
3843
# TODO: should this go inside plotly_build()?
3944
plotz <- lapply(plotz, function(p) {
@@ -245,8 +250,8 @@ get_domains <- function(nplots = 1, nrows = 1, margins = 0.01,
245250
"to the number of columns", call. = FALSE)
246251
}
247252
if (length(heights) != nrows) {
248-
stop("The length of the heights argument must be equal ",
249-
"to the number of rows", call. = FALSE)
253+
stop("The length of the heights argument is ", length(heights),
254+
", but the number of rows is ", nrows, call. = FALSE)
250255
}
251256
if (any(widths < 0) | any(heights < 0)) {
252257
stop("The widths and heights arguments must contain positive values")

R/utils.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
is.plotly <- function(x) inherits(x, "plotly")
1+
is.plotly <- function(x) {
2+
inherits(x, c("plotly_hash", "plotly_built", "plotly_subplot"))
3+
}
24

35
"%||%" <- function(x, y) {
46
if (length(x) > 0 || is_blank(x)) x else y

0 commit comments

Comments
 (0)