Skip to content

Commit 0b6f93b

Browse files
committed
Utilize instance.setProps to inform a dashRwidget about input events
1 parent 38f447f commit 0b6f93b

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

inst/htmlwidgets/plotly.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,38 @@ HTMLWidgets.widget({
301301
}
302302

303303

304+
// send user input event data to dashR
305+
// TODO: make this more consistent with Graph() props?
306+
if (instance.setProps) {
307+
graphDiv.on('plotly_relayout', function(d) {
308+
instance.setProps({"input_plotly_relayout": JSON.stringify(d) });
309+
});
310+
graphDiv.on('plotly_hover', function(d) {
311+
var val = JSON.stringify(eventDataWithKey(d));
312+
instance.setProps({"input_plotly_hover": val});
313+
});
314+
graphDiv.on('plotly_click', function(d) {
315+
var val = JSON.stringify(eventDataWithKey(d));
316+
instance.setProps({"input_plotly_click": val});
317+
});
318+
graphDiv.on('plotly_selected', function(d) {
319+
var val = JSON.stringify(eventDataWithKey(d));
320+
instance.setProps({"input_plotly_selected": val});
321+
});
322+
graphDiv.on('plotly_unhover', function(eventData) {
323+
instance.setProps({"input_plotly_hover": null});
324+
});
325+
graphDiv.on('plotly_doubleclick', function(eventData) {
326+
instance.setProps({"input_plotly_click": null});
327+
});
328+
// 'plotly_deselect' is code for doubleclick when in select mode
329+
graphDiv.on('plotly_deselect', function(eventData) {
330+
instance.setProps({"input_plotly_selected": null});
331+
instance.setProps({"input_plotly_click": null});
332+
});
333+
}
334+
335+
304336
// Given an array of {curveNumber: x, pointNumber: y} objects,
305337
// return a hash of {
306338
// set1: {value: [key1, key2, ...], _isSimpleKey: false},

0 commit comments

Comments
 (0)