Skip to content

Commit 0f9fd8f

Browse files
committed
dont srcify layout attributes
1 parent d06a053 commit 0f9fd8f

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

R/utils.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ verify_attr_names <- function(p) {
444444
verify_attr_spec <- function(p) {
445445
if (!is.null(p$x$layout)) {
446446
p$x$layout <- verify_attr(
447-
p$x$layout, Schema$layout$layoutAttributes
447+
p$x$layout, Schema$layout$layoutAttributes, layoutAttr = TRUE
448448
)
449449
}
450450
for (tr in seq_along(p$x$data)) {
@@ -459,7 +459,7 @@ verify_attr_spec <- function(p) {
459459
p
460460
}
461461

462-
verify_attr <- function(proposed, schema) {
462+
verify_attr <- function(proposed, schema, layoutAttr = FALSE) {
463463
for (attr in names(proposed)) {
464464
attrSchema <- schema[[attr]] %||% schema[[sub("[0-9]+$", "", attr)]]
465465
# if schema is missing (i.e., this is an un-official attr), move along
@@ -489,7 +489,7 @@ verify_attr <- function(proposed, schema) {
489489

490490
# tag 'src-able' attributes (needed for api_create())
491491
isSrcAble <- !is.null(schema[[paste0(attr, "src")]]) && length(proposed[[attr]]) > 1
492-
if (isDataArray || isSrcAble) {
492+
if ((isDataArray || isSrcAble) && !isTRUE(layoutAttr)) {
493493
proposed[[attr]] <- structure(proposed[[attr]], apiSrc = TRUE)
494494
}
495495

@@ -517,7 +517,7 @@ verify_attr <- function(proposed, schema) {
517517

518518
# do the same for "sub-attributes"
519519
if (identical(role, "object") && is.recursive(proposed[[attr]])) {
520-
proposed[[attr]] <- verify_attr(proposed[[attr]], schema[[attr]])
520+
proposed[[attr]] <- verify_attr(proposed[[attr]], schema[[attr]], layoutAttr = layoutAttr)
521521
}
522522
}
523523

tests/testthat/test-api.R

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@
118118
# expect_length(strsplit(x, ":")[[1]], 3)
119119
# }
120120
#
121+
# expect_not_srcified <- function(x) {
122+
# expect_true(is.null(x))
123+
# }
124+
#
121125
# # src-ifies data arrays, but not arrayOk of length 1
122126
# p <- plot_ly(x = 1:10, y = 1:10, marker = list(color = "red"))
123127
# res <- api_create(p)
@@ -138,9 +142,9 @@
138142
# api_create()
139143
# trace <- res$figure$frames[[1]]$data[[1]]
140144
# expect_srcified(trace$marker$colorsrc)
141-
#
142-
# # can src-ify layout.xaxis.tickvals
145+
#
146+
# # doesn't src-ify layout arrays (layout.xaxis.tickvals)
143147
# res <- api_create(ggplot() + geom_bar(aes(1:10)))
144-
# expect_srcified(res$figure$layout$xaxis$tickvalssrc)
145-
#
148+
# expect_not_srcified(res$figure$layout$xaxis$tickvalssrc)
149+
#
146150
# })

0 commit comments

Comments
 (0)