Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

* Closed #2337: Creating a new `event_data()` handler no longer causes a spurious reactive update of existing `event_data()`s. (#2339)

* Closed #2385: `"parcoords"`, `"parcats"` and `"splom"` traces now work when `values` is a length 1 vector (also, more generally, attributes that expect a list of objects should have those objects "verified" correctly now).

# 4.10.4

## Improvements
Expand Down
14 changes: 13 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,19 @@ verify_attr <- function(proposed, schema, layoutAttr = FALSE) {

# do the same for "sub-attributes"
if (identical(role, "object") && is.recursive(proposed[[attr]])) {
proposed[[attr]] <- verify_attr(proposed[[attr]], attrSchema, layoutAttr = layoutAttr)
# Some attributes (e.g., dimensions, transforms) are actually
# a list of objects (even though they, confusingly, have role: object)
# In those cases, we actually want to verify each list element
attr_ <- sub("s$", "", attr)
is_list_attr <- ("items" %in% names(attrSchema)) &&
(attr_ %in% names(attrSchema$items))
if (is_list_attr) {
proposed[[attr]] <- lapply(proposed[[attr]], function(x) {
verify_attr(x, attrSchema$items[[attr_]])
})
} else {
proposed[[attr]] <- verify_attr(proposed[[attr]], attrSchema, layoutAttr = layoutAttr)
}
}
}

Expand Down
20 changes: 20 additions & 0 deletions tests/testthat/test-plotly-parcats.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
expect_traces <- function(p, n.traces, name) {
stopifnot(is.numeric(n.traces))
L <- expect_doppelganger_built(p, paste0("plotly-", name))
expect_equivalent(length(L$data), n.traces)
L
}

test_that("values property has a class of AsIs", {
p <- plot_ly(
dimensions = list(
list(values = "A"),
list(values = "B")
),
type = "parcats"
)
l <- expect_traces(p, 1, "parcats-data-array")
tr <- l$data[[1]]$dimensions
expect_true(inherits(tr[[1]]$values, "AsIs"))
expect_true(inherits(tr[[2]]$values, "AsIs"))
})
20 changes: 20 additions & 0 deletions tests/testthat/test-plotly-parcoords.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
expect_traces <- function(p, n.traces, name) {
stopifnot(is.numeric(n.traces))
L <- expect_doppelganger_built(p, paste0("plotly-", name))
expect_equivalent(length(L$data), n.traces)
L
}

test_that("values property has a class of AsIs", {
p <- plot_ly(
dimensions = list(
list(label = "A", values = 3),
list(label = "B", values = 8)
),
type = "parcoords"
)
l <- expect_traces(p, 1, "parcoords-data-array")
tr <- l$data[[1]]$dimensions
expect_true(inherits(tr[[1]]$values, "AsIs"))
expect_true(inherits(tr[[2]]$values, "AsIs"))
})
22 changes: 20 additions & 2 deletions tests/testthat/test-plotly-splom.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@


expect_traces <- function(p, n.traces, name) {
stopifnot(is.numeric(n.traces))
L <- expect_doppelganger_built(p, paste0("plotly-", name))
expect_equivalent(length(L$data), n.traces)
L
}

test_that("No cartesian axes are supplied to a splom chart", {

Expand All @@ -12,3 +16,17 @@ test_that("No cartesian axes are supplied to a splom chart", {
)

})

test_that("values property has a class of AsIs", {
p <- plot_ly(
type = "splom",
dimensions = list(
list(values = 1, label = "A"),
list(values = 2, label = "B")
)
)
l <- expect_traces(p, 1, "parcats-data-array")
tr <- l$data[[1]]$dimensions
expect_true(inherits(tr[[1]]$values, "AsIs"))
expect_true(inherits(tr[[2]]$values, "AsIs"))
})
Loading