dygraphs icon indicating copy to clipboard operation
dygraphs copied to clipboard

Data.frame is not supported when first columns is a date.time

Open vspinu opened this issue 7 years ago • 3 comments

> 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'.

vspinu avatar Nov 15 '17 22:11 vspinu

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.

helgasoft avatar Mar 03 '19 21:03 helgasoft

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.

fdetsch avatar Apr 24 '19 08:04 fdetsch

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 !

phileas-condemine avatar Jul 18 '19 11:07 phileas-condemine