dygraphs
dygraphs copied to clipboard
Data.frame is not supported when first columns is a date.time
> dygraph(data.frame(date = as.Date(Sys.time()), metric = 1))
Error in dygraph(data.frame(date = as.Date(Sys.time()), metric = 1)) :
Unsupported type passed to argument 'data'.
> dygraph(data.frame(date = (Sys.time()), metric = 1))
Error in dygraph(data.frame(date = (Sys.time()), metric = 1)) :
Unsupported type passed to argument 'data'.
It's by design, comes from the following line in dygraph's code:
else if (is.list(data) && is.numeric(data[[1]])) { # then data is considered OK
i.e. if data is data.frame, the first column must be numeric.
But I agree with you that Date and DateTime makes sense and should be a valid 1st-column type for data.frame.
I agree, support for timestamps inheriting from POSIX* and the like are highly desirable when feeding data.frames into dygraph()
. At the moment, I tend to convert my data to xts::xts()
every time I create an interactive graph, which also means an additional dependency in self-made packages using dygraphs.
If you convert the data.frame to data.table it works when data[[1]] is a Date.
RepEx :
data <- data.frame(Date=seq.Date(Sys.Date()-100,Sys.Date(),1),val=sample(1:10,101,replace=T))
dygraph(data=data)%>%dygraphs::dyRangeSelector()# error
dygraph(data=data.table::data.table(data))%>%dygraphs::dyRangeSelector() # OK !