yur*_*leb 3 markdown r dygraphs r-dygraphs
在这里的对话之后,有没有办法在网格中组织输出dygraph?要连续显示一个或多个图表.
下面的代码将生成垂直排列的4个dygraphs.有没有办法在4x4网格中组织它们?
我尝试使用tags$div但它将所有图形包装在一个div中.有没有办法将CSS属性display: inline-block;应用于每个dygraph小部件?或任何其他更好的方法?
```{r}
library(dygraphs)
library(htmltools)
makeGraphs = function(i){
dygraph(lungDeaths[, i], width = 300, height = 300, group = "lung-deaths")%>%
dyOptions(strokeWidth = 3) %>%
dyRangeSelector(height = 20)
}
lungDeaths <- cbind(mdeaths, fdeaths, ldeaths, mdeaths)
res <- lapply(1:4, makeGraphs )
htmltools::tagList(tags$div(res, style = "width: 620px; padding: 1em; border: solid; background-color:#e9e9e9"))
```
Run Code Online (Sandbox Code Playgroud)
当前输出截图:
我想我已经弄明白了,不确定它是最好的解决方案,但添加带有display:inline-block;属性的包装div 似乎运行得很好.
我刚刚将这一行添加到生成每个dygraph的函数中:
htmltools::tags$div(theGraph, style = "padding:10px; width: 250px; border: solid; background-color:#e9e9e9; display:inline-block;")
Run Code Online (Sandbox Code Playgroud)
所以更新后的代码如下所示:
```{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)
```
Run Code Online (Sandbox Code Playgroud)