Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access persistent click/hover data in shiny, addresses #1401 #1409

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 44 additions & 2 deletions inst/htmlwidgets/plotly.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,29 +277,71 @@ HTMLWidgets.widget({
);
});
graphDiv.on('plotly_hover', function(d) {

Shiny.onInputChange(
".clientValue-plotly_hover-" + x.source,
JSON.stringify(eventDataWithKey(d))
);

// When persistent selection is enabled (either through
// shift or highlight()), remember click data
if (x.highlight.persistentShift) {
var dShift = graphDiv._shiny_plotly_hover || {points: []};
var pts = [].concat(dShift.points, d.points);
var d = {points: pts, event: d.event};
graphDiv._shiny_plotly_hover = d;
} else {
graphDiv._shiny_plotly_hover = undefined;
}

Shiny.onInputChange(
".clientValue-plotly_hover_persist_on_shift-" + x.source,
JSON.stringify(eventDataWithKey(d))
);

});
graphDiv.on('plotly_click', function(d) {

Shiny.onInputChange(
".clientValue-plotly_click-" + x.source,
".clientValue-plotly_click-" + x.source,
JSON.stringify(eventDataWithKey(d))
);

// When persistent selection is enabled (either through
// shift or highlight()), remember click data
if (x.highlight.persistentShift) {
var dShift = graphDiv._shiny_plotly_click || {points: []};
var pts = [].concat(dShift.points, d.points);
var d = {points: pts, event: d.event};
graphDiv._shiny_plotly_click = d;
} else {
graphDiv._shiny_plotly_click = undefined;
}

Shiny.onInputChange(
".clientValue-plotly_click_persist_on_shift-" + x.source,
JSON.stringify(eventDataWithKey(d))
);

});

graphDiv.on('plotly_selected', function(d) {
Shiny.onInputChange(
".clientValue-plotly_selected-" + x.source,
JSON.stringify(eventDataWithKey(d))
);
});

graphDiv.on('plotly_unhover', function(eventData) {
Shiny.onInputChange(".clientValue-plotly_hover-" + x.source, null);
if (!x.highlight.persistentShift) {
Shiny.onInputChange(".clientValue-plotly_hover-" + x.source, null);
}
});

graphDiv.on('plotly_doubleclick', function(eventData) {
Shiny.onInputChange(".clientValue-plotly_click-" + x.source, null);
});

// 'plotly_deselect' is code for doubleclick when in select mode
graphDiv.on('plotly_deselect', function(eventData) {
Shiny.onInputChange(".clientValue-plotly_selected-" + x.source, null);
Expand Down