Displaying multiple dygraphs on a grid in R-Markdown

房东的猫 提交于 2019-12-06 03:24:46

I think I figured it out, not sure its the best solution, but adding a wrapper div with a display:inline-block; property seems to work quite well.

I just added this line to the function that generates each dygraph:

htmltools::tags$div(theGraph, style = "padding:10px; width: 250px; border: solid; background-color:#e9e9e9; display:inline-block;")

so the updated code looks like this:

```{r graphs}
library(dygraphs)
library(htmltools)


makeGraphs = function(i){
  theGraph <- dygraph(lungDeaths[, i], width = 400, height = 300, group = "lung-deaths")%>%
    dyOptions(strokeWidth = 3) %>%
    dyRangeSelector(height = 20)

  htmltools::tags$div(theGraph, style = "padding:10px; width: 450px; border: solid; background-color:#e9e9e9; display:inline-block;")

}



lungDeaths <- cbind(mdeaths, fdeaths, ldeaths, mdeaths)
res <- lapply(1:4, makeGraphs )
htmltools::tagList(res) 

```

Output Screenshot:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!