I have a loop in my script to iterate over sites and produce the dygraphs for the time series data. It really needs to be in a loop due to the number of sites I am looking at. I want to knit to a html document from this but printing dygraphs doesn't work in a loop (in markdown at least). This has been covered here, and here before but there wasn't a solution, though these were several years ago, so wondering if there is an answer now....
This is supposed to work according to one of those links, but the result prints the 'i' value, but the dygraph does not get output.
library(dygraphs)
library(htmltools)
lungDeaths <- cbind(mdeaths, fdeaths)
lungDeaths <- cbind(mdeaths, fdeaths)
for(i in 1:2){
print(i)
res <- lapply(1:2, function(i) dygraph(lungDeaths[, i]) )
htmltools::tagList(res)
}
Does anyone know of a solution for this now?