Skip to content

Commit 17466a3

Browse files
authored
Merge pull request #1611 from ropensci/shiny-event-data-key
Improvements to algorithm for attaching key attribute for shiny's event data, fixes #1610
2 parents 2856731 + 30e3997 commit 17466a3

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

inst/htmlwidgets/plotly.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,13 @@ HTMLWidgets.widget({
263263
for (var i = 0; i < attrsToAttach.length; i++) {
264264
var attr = trace[attrsToAttach[i]];
265265
if (Array.isArray(attr)) {
266-
// pointNumber can be an array (e.g., heatmaps)
267-
// TODO: can pointNumber be 3D?
268-
obj[attrsToAttach[i]] = typeof pt.pointNumber === "number" ?
269-
attr[pt.pointNumber] : attr[pt.pointNumber[0]][pt.pointNumber[1]];
266+
if (typeof pt.pointNumber === "number") {
267+
obj[attrsToAttach[i]] = attr[pt.pointNumber];
268+
} else if (Array.isArray(pt.pointNumber)) {
269+
obj[attrsToAttach[i]] = attr[pt.pointNumber[0]][pt.pointNumber[1]];
270+
} else if (Array.isArray(pt.pointNumbers)) {
271+
obj[attrsToAttach[i]] = pt.pointNumbers.map(function(idx) { return attr[idx]; });
272+
}
270273
}
271274
}
272275
return obj;

0 commit comments

Comments
 (0)