Getting point coordinates by clicking a dygraph within RStudio viewer pane

Viewed 679

Here's a simple dygraph:

library(dygraphs)  
dg <- dygraph(ldeaths)  
dg

As your mouse moves over the series, individual values are displayed. I'd like to click on a point and have the x coordinate (i.e., the date) displayed on the console or saved to a variable. How can I accomplish that? Looks like the answer has to do with dyCallbacks(), but I can't really figure it out. e.g.,

> d <- dg %>% dyCallbacks(pointClickCallback = 'function(e, p) {return
> p.x;}')   d$x$attrs$pointClickCallback   [1] "function(e, p) {return
> p.x;}"   attr(,"class")   [1] "JS_EVAL"

Thanks in advance,
Fabio

1 Answers
Related