对于循环遍历dygraph在R中不起作用

dim*_*_ps 11 r dygraphs r-markdown

有一些奇怪的行为dygraph.

使用for循环时,dygraph我没有结果.

library(dygraphs)
lungDeaths <- cbind(mdeaths, fdeaths)

for(i in 1:2){
  dygraph(lungDeaths[, i])
}
Run Code Online (Sandbox Code Playgroud)

另一方面,当我使用lapply我确实得到预期的结果

lapply(1:2, function(i) dygraph(lungDeaths[, i]))
Run Code Online (Sandbox Code Playgroud)

我实际上想在我自己的数据集中使用for循环R Markdown并迭代不同的列,但即使我使用lapply"解决方法",它也不会绘制dygraphs

R Markdown代码

---
title: "Untitled"
author: "dimitris_ps"
date: "28 May 2015"
output: html_document
---

```{r}
library(dygraphs)
lungDeaths <- cbind(mdeaths, fdeaths)
lapply(1:2, function(i) dygraph(lungDeaths[, i]))
```
Run Code Online (Sandbox Code Playgroud)

而当我逐列运行它时,它的工作原理

---
title: "Untitled"
author: "dimitris_ps"
date: "28 May 2015"
output: html_document
---

```{r echo=FALSE}
library(dygraphs)
lungDeaths <- cbind(mdeaths, fdeaths)
```

```{r}
dygraph(lungDeaths[, 1])
dygraph(lungDeaths[, 2])
```
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激.

会话信息

R version 3.2.0 (2015-04-16)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252   
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] dygraphs_0.4.3 devtools_1.7.0

loaded via a namespace (and not attached):
[1] htmltools_0.2.6 tools_3.2.0     yaml_2.1.13     rmarkdown_0.6.1 digest_0.6.8 
Run Code Online (Sandbox Code Playgroud)

Yih*_*Xie 14

只是包装从列表输出lapply()htmltools::tagList(),如

```{r}
library(dygraphs)
lungDeaths <- cbind(mdeaths, fdeaths)
res <- lapply(1:2, function(i) dygraph(lungDeaths[, i]))
htmltools::tagList(res)
```
Run Code Online (Sandbox Code Playgroud)