title: R Shiny - sankey plot with click events
body: <p>I'm trying to create an <strong>R</strong> shiny dashboard with a Sankey plot. I want to be able to extract the name of the clicked node.</p>
  <p>There are two libraries that can plot Sankey diagrams, <code>networkD3</code> and <code>googleVis</code>. <code>networkD3</code> does allow you to monitor click events, even though another type of plot implemented in the same library comes with such feature (<code>forceNetwork()</code>).</p>
  <p><code>googleVis</code> package however has a function <code>gvisSankey</code> that can create sankey plots and as an option you can pass a parameter <code>gvis.listener.jscode</code> that should be able to capture it.</p>
  <p>I'm afraid I'm not that familiar with JS and I'm struggling to get what I'm looking for. This is how far I managed to get:</p>
  <pre><code>library(shiny)
  library(googleVis)
  
  datSK &lt;- data.frame(From=c(rep(&quot;A&quot;,3), rep(&quot;B&quot;, 3)),
                      To=c(rep(c(&quot;X&quot;, &quot;Y&quot;, &quot;Z&quot;),2)),
                      Weight=c(5,7,6,2,9,4))
  
  SERVER &lt;- function(input, output, session){
    sankey_click &lt;- sprintf(&quot;var text = chart.getSelection();
   Shiny.onInputChange('%s', text.toString())&quot;, session$ns('text'))
    output$sankey &lt;- renderGvis(
      gvisSankey(datSK, from=&quot;From&quot;, to=&quot;To&quot;, weight=&quot;Weight&quot;,
                 options=list(gvis.listener.jscode = sankey_click, 
                              sankey = &quot;{node: {interactivity: true, width: 50}}&quot;))
    )
    
    click_event &lt;- reactive({input$text})
    output$click &lt;- renderText(click_event())
    
  }
  
  UI &lt;- fluidPage(
    fluidRow(column(12, htmlOutput(&quot;sankey&quot;))),
    fluidRow(column(12, verbatimTextOutput(&quot;click&quot;)))  
  )
  
  shinyApp(ui = UI, server = SERVER)
  </code></pre>
  <p>As you can see, all I get is <code>object Object</code>.</p>