Binding to click events in R

I’m having trouble figuring out how to bind callback functions to click events in R charts with the JavaScript code given in: I’m able to get my plotly plot to show up in RStudio but how do I also incorporate the JavaScript in order to be able to click on a point. Do I have to run my code through Java.