Skip to content

Commit 9aa0e86

Browse files
authored
Merge pull request #1408 from ropensci/prevent-selected-event-on-click
'plotly_selected' is too eager to clear/update
2 parents e266a3c + 1cccba5 commit 9aa0e86

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

inst/htmlwidgets/plotly.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,18 @@ HTMLWidgets.widget({
289289
);
290290
});
291291
graphDiv.on('plotly_selected', function(d) {
292-
Shiny.onInputChange(
293-
".clientValue-plotly_selected-" + x.source,
294-
JSON.stringify(eventDataWithKey(d))
295-
);
292+
// If 'plotly_selected' has already been fired, and you click
293+
// on the plot afterwards, this event fires `undefined`?!?
294+
// That might be considered a plotly.js bug, but it doesn't make
295+
// sense for this input change to occur if `d` is falsy because,
296+
// even in the empty selection case, `d` is truthy (an object),
297+
// and the 'plotly_deselect' event will reset this input
298+
if (d) {
299+
Shiny.onInputChange(
300+
".clientValue-plotly_selected-" + x.source,
301+
JSON.stringify(eventDataWithKey(d))
302+
);
303+
}
296304
});
297305
graphDiv.on('plotly_unhover', function(eventData) {
298306
Shiny.onInputChange(".clientValue-plotly_hover-" + x.source, null);

0 commit comments

Comments
 (0)