Search code examples
rtime-seriesxtsdygraphstibble

Dygraph on tibble converted to xts, with 3001 series


I am trying to print a shiny dygraph, which has data for 3001 cities in a tibble, pretty much like TRI, which I am converting to xts like this:

tbl_xts(dados, cols_to_xts = "totalCases", spread_by = "city")

But this hangs forever. I presume it's because 3001 new columns are created. Right ?

Then I try to convert using regular xts() and it's very quick, but it doesn't separate the series in individual lines.

How to do this ?


Solution

  • Well, what I've accomplished after some time is that the first attempt using tbl_xts is the right way to separate the graph in individual lines, but then I use a filter to only create columns for the cities which are contained in the shiny input. So it's now really fast :)

    Like:

    xtsdata <- tbl_xts(dados %>% filter(city%in%dados$city), cols_to_xts = "totalCases", spread_by = "city")
          g2 <- dygraph(xtsdata, xlab='Dia', ylab='Casos (acumulado)', main="Gráfico temporal")