diff --git a/inst/htmlwidgets/plotly.js b/inst/htmlwidgets/plotly.js index 808036020d..8c1635975c 100644 --- a/inst/htmlwidgets/plotly.js +++ b/inst/htmlwidgets/plotly.js @@ -301,6 +301,38 @@ HTMLWidgets.widget({ } + // send user input event data to dashR + // TODO: make this more consistent with Graph() props? + var dashRwidgets = window.dashRwidgets || {}; + var dashRmode = typeof el.setProps === "function" && + typeof dashRwidgets.htmlwidget === "function"; + if (dashRmode) { + graphDiv.on('plotly_relayout', function(d) { + el.setProps({"input_plotly_relayout": d}); + }); + graphDiv.on('plotly_hover', function(d) { + el.setProps({"input_plotly_hover": eventDataWithKey(d)}); + }); + graphDiv.on('plotly_click', function(d) { + el.setProps({"input_plotly_click": eventDataWithKey(d)}); + }); + graphDiv.on('plotly_selected', function(d) { + el.setProps({"input_plotly_selected": eventDataWithKey(d)}); + }); + graphDiv.on('plotly_unhover', function(eventData) { + el.setProps({"input_plotly_hover": null}); + }); + graphDiv.on('plotly_doubleclick', function(eventData) { + el.setProps({"input_plotly_click": null}); + }); + // 'plotly_deselect' is code for doubleclick when in select mode + graphDiv.on('plotly_deselect', function(eventData) { + el.setProps({"input_plotly_selected": null}); + el.setProps({"input_plotly_click": null}); + }); + } + + // Given an array of {curveNumber: x, pointNumber: y} objects, // return a hash of { // set1: {value: [key1, key2, ...], _isSimpleKey: false},