I am trying to select manually the peaks and valleys from a noisy sinusoidal signal within a time series which is displayed on a dygraph using R. I create a simple example below.
x=seq(0.1,10,by=0.01)
y=sin(x)
ts = data.frame(x,y)
dygraph(ts)
dyCallbacks(ts,pointClickCallback = function(e, pt){alert(this.getValue(pt.idx,1))})
However I am not able to record the clicks on the peaks and valleys with the dycallbacks call. The error message I get is:
The arguments for JS() must be a character vector
The error is rising because you're giving the correct params to
dyCallbacks(dygraph, pointClickCallback)
which takes :dygraph
: Dygraph to add callbacks to.pointClickCallback
: A (JS) function to call when a data point is clicked. and the point that was clicked. i.e a character vector to be later on passed toJS()
function.So the correct code is :
Writing it to a file:
I think using
shiny
is definitely justifiable in this case as we're going to have easy access to baseR
functions:Non-shiny solution using only callbacks and js
Output in
peaks.csv