Skip to content

Commit e1b5f65

Browse files
committed
Sanitize kwargs from class "environment" before posting - Fixes #254
1 parent a97299c commit e1b5f65

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

R/plotly_POST.R

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,19 @@ plotly_POST <- function(x) {
3131
# empty keyword arguments can cause problems
3232
kwargs <- x[get_kwargs()]
3333
kwargs <- kwargs[sapply(kwargs, length) > 0]
34-
34+
35+
# class "environment" from $layout$enclos causes
36+
# Error in unclass(x) : cannot unclass an environment
37+
# in jsonlite::toJSON
38+
# (https://github.com/ropensci/plotly/issues/254)
39+
kwargs <- lapply(kwargs, function(i){
40+
if(class(i)=="list") {
41+
i[sapply(i, class) != "environment"]
42+
} else{
43+
i
44+
}
45+
})
46+
3547
# filename & fileopt are keyword arguments required by the API
3648
# (note they can also be specified by the user)
3749

0 commit comments

Comments
 (0)