@@ -112,23 +112,41 @@ from_JSON <- function(x, ...) {
112
112
jsonlite :: fromJSON(x , simplifyDataFrame = FALSE , simplifyMatrix = FALSE , ... )
113
113
}
114
114
115
- # plotlyjs properties that must _always_ be an array (even if length 1)
116
- get_boxed <- function () {
117
- c(" x" , " y" , " lat" , " lon" , " text" )
118
- }
119
-
120
115
add_boxed <- function (x ) {
121
116
for (i in seq_along(x $ data )) {
122
117
# some object keys require an array, even if length one
123
118
# one way to ensure atomic vectors of length 1 are not automatically unboxed,
124
119
# by to_JSON(), is to attach a class of AsIs (via I())
125
120
d <- x $ data [[i ]]
126
- idx <- names(d ) %in% get_boxed() & sapply(d , length ) == 1
121
+ idx <- names(d ) %in% get_boxed(d $ type % || % " scatter " ) & sapply(d , length ) == 1
127
122
if (any(idx )) x $ data [[i ]][idx ] <- lapply(d [idx ], I )
128
123
}
129
124
x
130
125
}
131
126
127
+ # plotlyjs properties that must _always_ be an array (even if length 1)
128
+ get_boxed <- function (type = " scatter" ) {
129
+ boxers [[type ]]
130
+ }
131
+
132
+ # if this ever needs updating see
133
+ # https://github.com/ropensci/plotly/issues/415#issuecomment-173353138
134
+ boxers <- list (
135
+ choropleth = c(" locations" , " z" , " text" ),
136
+ box = c(" x" , " y" ),
137
+ heatmap = c(" z" , " text" ),
138
+ histogram = c(" x" , " y" ),
139
+ histogram2d = c(" z" , " color" ),
140
+ mesh3d = c(" x" , " y" , " z" , " i" , " j" , " k" , " intensity" , " vertexcolor" , " facecolor" ),
141
+ # TODO: what to do about marker.colors?
142
+ pie = c(" labels" , " values" , " text" ),
143
+ scatter = c(" x" , " y" , " r" , " t" ),
144
+ scatter3d = c(" x" , " y" , " z" ),
145
+ scattergeo = c(" lon" , " lat" , " locations" ),
146
+ surface = c(" x" , " y" , " z" , " text" )
147
+ )
148
+
149
+
132
150
rm_asis <- function (x ) {
133
151
# jsonlite converts NULL to {} and NA to null (plotly prefers null to {})
134
152
# https://github.com/jeroenooms/jsonlite/issues/29
0 commit comments