Skip to content

Commit 7682f80

Browse files
committed
relay customdata in event_data()
1 parent 2bf4abc commit 7682f80

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

R/layers2traces.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,7 @@ geom2trace.GeomPath <- function(data, params, p) {
637637
y = data[["y"]],
638638
text = uniq(data[["hovertext"]]),
639639
key = data[["key"]],
640+
customdata = data[["customdata"]],
640641
frame = data[["frame"]],
641642
ids = data[["ids"]],
642643
type = "scatter",
@@ -667,6 +668,7 @@ geom2trace.GeomPoint <- function(data, params, p) {
667668
y = data[["y"]],
668669
text = if (isDotPlot) data[["key"]] else uniq(data[["hovertext"]]),
669670
key = data[["key"]],
671+
customdata = data[["customdata"]],
670672
frame = data[["frame"]],
671673
ids = data[["ids"]],
672674
type = "scatter",
@@ -720,6 +722,7 @@ geom2trace.GeomBar <- function(data, params, p) {
720722
y = y,
721723
text = uniq(data[["hovertext"]]),
722724
key = data[["key"]],
725+
customdata = data[["customdata"]],
723726
frame = data[["frame"]],
724727
ids = data[["ids"]],
725728
type = "bar",
@@ -747,6 +750,7 @@ geom2trace.GeomPolygon <- function(data, params, p) {
747750
y = data[["y"]],
748751
text = uniq(data[["hovertext"]]),
749752
key = data[["key"]],
753+
customdata = data[["customdata"]],
750754
frame = data[["frame"]],
751755
ids = data[["ids"]],
752756
type = "scatter",
@@ -778,6 +782,7 @@ geom2trace.GeomBoxplot <- function(data, params, p) {
778782
y = data[["y"]],
779783
hoverinfo = "y",
780784
key = data[["key"]],
785+
customdata = data[["customdata"]],
781786
frame = data[["frame"]],
782787
ids = data[["ids"]],
783788
type = "box",
@@ -812,6 +817,7 @@ geom2trace.GeomText <- function(data, params, p) {
812817
text = data[["label"]],
813818
hovertext = data[["hovertext"]],
814819
key = data[["key"]],
820+
customdata = data[["customdata"]],
815821
frame = data[["frame"]],
816822
ids = data[["ids"]],
817823
textfont = list(
@@ -850,6 +856,7 @@ geom2trace.GeomTile <- function(data, params, p) {
850856
z = matrix(g$fill_plotlyDomain, nrow = length(y), ncol = length(x), byrow = TRUE),
851857
text = matrix(g$hovertext, nrow = length(y), ncol = length(x), byrow = TRUE),
852858
key = data[["key"]],
859+
customdata = data[["customdata"]],
853860
frame = data[["frame"]],
854861
ids = data[["ids"]],
855862
colorscale = setNames(colScale, NULL),
@@ -945,6 +952,7 @@ make_error <- function(data, params, xy = "x") {
945952
y = data[["y"]],
946953
text = uniq(data[["hovertext"]]),
947954
key = data[["key"]],
955+
customdata = data[["customdata"]],
948956
frame = data[["frame"]],
949957
ids = data[["ids"]],
950958
type = "scatter",

inst/examples/shiny/event_data/app.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ server <- function(input, output, session) {
1515

1616
output$plot <- renderPlotly({
1717
if (identical(input$plotType, "ggplotly")) {
18-
p <- ggplot(mtcars, aes(x = mpg, y = wt, key = nms)) + geom_point()
18+
p <- ggplot(mtcars, aes(x = mpg, y = wt, customdata = nms)) + geom_point()
1919
ggplotly(p) %>% layout(dragmode = "select")
2020
} else {
21-
plot_ly(mtcars, x = ~mpg, y = ~wt, key = nms) %>%
21+
plot_ly(mtcars, x = ~mpg, y = ~wt, customdata = nms) %>%
2222
layout(dragmode = "select")
2323
}
2424
})

inst/htmlwidgets/plotly.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,10 @@ HTMLWidgets.widget({
236236
obj.z = pt.z;
237237
}
238238

239+
if (pt.hasOwnProperty("customdata")) {
240+
obj.customdata = pt.customdata;
241+
}
242+
239243
/*
240244
TL;DR: (I think) we have to select the graph div (again) to attach keys...
241245

0 commit comments

Comments
 (0)