Plotly.js events in ggplotly + Shiny

I can’t seem to get any events to work properly using ggplotly. I have two use cases:

  1. I want my application to perform an action if a user clicks a data point. Following the documentation here, I tried to intercept “plotly_click” events. With Shiny and ggplotly, I don’t control the lifecycle of my plots directly, so using jQuery:

    $(’#chart6’).on(‘plotly_click’, function(evt) {
    console.log(evt);
    });

… gives me nothing. Which is strange, because chart6 is the parent div of the plot-container element.

$('*').on('plotly_click', function(evt) {
    console.log(evt);
});

… gives me m.Event {type: “plotly_click”, …}. But evt has no points attribute, and evt.data is explicitly undefined. So the event has no information identifying which point I clicked on!

2 ) I want to disable the default hoverinfo/tooltip, and use the evt to create my own.

$('*').on('plotly_hover', function(evt) {
    console.log(evt);
});

… gives me m.Event {type: “plotly_hover”, …}. But again there is no useful information in this event!

Is ggplotly even compatible with plotly.js events?

Hiya! Plotly now has improved and consolidated Plotly.js event documentation here:

Please feel free to suggest documentation improvements in a pull request:

https://github.com/plotly/documentation/tree/source-design-merge/_posts/plotly_js/events