Skip to content

Commit b7d0904

Browse files
committed
restrict to atomic vectors
1 parent c7d8c51 commit b7d0904

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

R/plotly_build.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ plotly_build.plotly <- function(p) {
103103
# I'm looking at you scattergeo...
104104
tr <- trace[names(trace) %in% c(npscales(), special_attrs(trace), dataArrayAttrs, "text")]
105105
# TODO: does it make sense to "train" matrices/2D-tables (e.g. z)?
106-
tr <- tr[vapply(tr, function(x) is.null(dim(x)), logical(1))]
106+
tr <- tr[vapply(tr, function(x) is.null(dim(x)) && is.atomic(x), logical(1))]
107107
builtData <- tibble::as_tibble(tr)
108108

109109
# avoid clobbering I() (i.e., variables that shouldn't be scaled)

tests/testthat/test-plotly.R

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,27 @@ test_that("Discrete variable mapped to x creates horizontal bar chart", {
161161
expect_equal(unique(o), "h")
162162
expect_equal(unique(types), "histogram")
163163
})
164+
165+
166+
167+
test_that("Complex example works", {
168+
# note how median (the variable) doesn't exist in the second layer
169+
p <- txhousing %>%
170+
plot_ly(x = ~date, y = ~median) %>%
171+
group_by(city) %>%
172+
add_lines(alpha = 0.2, name = "Texan Cities", hoverinfo = "none") %>%
173+
group_by(date) %>%
174+
summarise(
175+
q1 = quantile(median, 0.25, na.rm = TRUE),
176+
m = median(median, na.rm = TRUE),
177+
q3 = quantile(median, 0.75, na.rm = TRUE)
178+
) %>%
179+
add_lines(y = ~m, color = I("red"), name = "median") %>%
180+
add_ribbons(ymin = ~q1, ymax = ~q3, color = I("red"), name = "IQR")
181+
182+
l <- expect_traces(p, 3, "time-series-summary")
183+
})
184+
185+
186+
187+

0 commit comments

Comments
 (0)