plotly.R icon indicating copy to clipboard operation
plotly.R copied to clipboard

Customdata format variations

Open cnftstats opened this issue 3 years ago • 0 comments

There seems to be a lot of variations regarding the format in which the customdata is structured.

Showcase:

library(plotly)
library(htmlwidgets)

js <- "function(el, x) {
         el.on('plotly_click', function(d) {
           console.log(d);
           console.log(d.points[0].data.customdata[0]);
       });
       }"

X <- data.frame(x = c(1, 2, 1, 2), y = c(1, 1, 2, 2), z = as.character(1:4), mydata = letters[1:4])

gg <- ggplot(X, aes(x = x, y = y, customdata = mydata)) + geom_tile(aes(fill = z))

ggplotly(gg) %>% onRender(js)

image

Same as above, except z is now numerical:

X <- data.frame(x = c(1, 2, 1, 2), y = c(1, 1, 2, 2), z = 1:4, mydata = letters[1:4])

image

More information in this Stackoverflow post.

cnftstats avatar Apr 08 '22 08:04 cnftstats