title: How to make scatterplot points open a hyperlink using ggplotly - R
body: <p>I'd like to make my scatterplot points clickable and have each point's respective hyperlink open when clicked. I am trying to do this using ggplotly.
  There is a simple way to do this when building the plot using plotly()(see first example below). However, when running it on ggplotly, an empty webpage opens when I click.</p>
  <p>Anyone know how I can make this work with the code below? Could there be a solution on the OnRender portion of the code (not familiar with javascript)?
  The first code chunk using plotly works. The second code chunk is my basic attempt at thisusing ggplotly, which does not work.</p>
  <p>Any guidance on this would be amazing! thanks in advance</p>
  <pre><code>library(plotly)
  library(htmlwidgets)
  library(dplyr)
  
  mtcars$url &lt;- paste0(&quot;http://google.com/search?q=&quot;, gsub(&quot; &quot;, &quot;+&quot;, rownames(mtcars)))
  
  #1. Using plotly
  p &lt;- plot_ly(mtcars, x = ~wt, y = ~mpg) %&gt;%
    add_markers(customdata = ~url)
  onRender(p, &quot;
           function(el, x) {
           el.on('plotly_click', function(d) {
           var url = d.points[0].customdata;
           window.open(url);
           });
           }
           &quot;)
  
  #2. Using ggplotly`
  p &lt;- ggplot(data = mtcars, aes(x = wt, y = mpg))+
    geom_point()
  pp &lt;- ggplotly(p)
  pp  &lt;- add_markers(pp, customdata = ~url)
  onRender(pp, &quot;
           function(el, x) {
           el.on('plotly_click', function(d) {
           var url = d.points[0].customdata;
           url
           window.open(url);
           });
           }
           &quot;)
  </code></pre>