plotly click events (without shiny, in console)

Hi all! :slight_smile: Is it possible to log/return plotly data in a non reactive shiny output (e.g. rmarkdown html?)

Rmd chunk

library(plotly);library(shiny);
read.csv("https://raw.githubusercontent.com/plotly/datasets/master/2011_us_ag_exports.csv") %>% 
  plot_geo(locationmode = "USA-states") %>% 
  add_trace(
    z = ~total.exports,
    locations = ~code,
    color = ~total.exports
  ) %>% 
  layout(geo = list(scope = 'usa',projection = list(type = 'albers usa'))) %>% 
  div(id = "test-map")

browser console

plot_id = $("#test-map").find(".plotly").attr("id");

$("#" + plot_id).on('plotly_click', d => {
  var pt = (d.points || [])[0]
  console.log(pt.location);
 });

I'd expect the above to return "CO" or "AZ" after clicking on that state, but haven't been able to find a way to get it working.

For what its worth, I am familiar with client side linking (plotly book) and crosstalk but haven't found a way to apply the same underlying theory within a browser console.

Would appreciate any thoughts!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.