Skip to content

Commit 6277739

Browse files
committed
stringify JSON before passing to R
1 parent eef0368 commit 6277739

File tree

4 files changed

+10
-15
lines changed

4 files changed

+10
-15
lines changed

R/ggplotly.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ gg2list <- function(p, width = NULL, height = NULL, source = "A") {
315315
# npc is on a 0-1 scale of the _entire_ device,
316316
# but these units _should_ be wrt to the plotting region
317317
# multiplying the offset by 2 seems to work, but this is a terrible hack
318-
offset <- 2 * offset
318+
offset <- 1.75 * offset
319319
x <- if (xy == "x") 0.5 else offset
320320
y <- if (xy == "x") offset else 0.5
321321
gglayout$annotations <- c(

R/print.R

+4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ as.widget <- function(x, ...) {
4040
list(b = 40, l = 60, t = 25, r = 10),
4141
p$layout$margin %||% list()
4242
)
43+
p$config$modeBarButtonsToRemove <- modifyList(
44+
list("sendDataToCloud"),
45+
p$config$modeBarButtonsToRemove %||% list()
46+
)
4347
p$base_url <- get_domain()
4448
# customize the JSON serializer (for htmlwidgets)
4549
attr(p, 'TOJSON_FUNC') <- to_JSON

R/shiny.R

+1-13
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,5 @@ event_data <- function(event = c("plotly_hover", "plotly_click", "plotly_selecte
5353
"from within a reactive shiny context.")
5454
}
5555
val <- session$input[[sprintf(".clientValue-%s-%s", event[1], source)]]
56-
57-
# TODO: report this!
58-
if (event[1] == "plotly_selected" && is.character(val)) {
59-
nms <- unique(names(val))
60-
d <- list()
61-
for (i in nms) {
62-
d[[i]] <- val[names(val) %in% i]
63-
}
64-
# TODO: try to convert numerics?
65-
data.frame(d, stringsAsFactors = FALSE)
66-
} else {
67-
val
68-
}
56+
if (is.null(val)) val else jsonlite::fromJSON(val)
6957
}

inst/htmlwidgets/plotly.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ HTMLWidgets.widget({
5959
attachKey("key");
6060
return obj;
6161
});
62-
Shiny.onInputChange(".clientValue-" + eventType + "-" + x.source, d);
62+
Shiny.onInputChange(
63+
".clientValue-" + eventType + "-" + x.source,
64+
JSON.stringify(d)
65+
);
6366
};
6467
};
6568

0 commit comments

Comments
 (0)