是否可以从循环或函数内部使用ggplotly()或datatable()在 RMarkdown 中for?例子:
---
title: "Using `ggplotly` and `DT` from a `for` loop in Rmarkdown"
output: html_document
---
```{r setup, include=FALSE}
library(ggplot2); library(DT)
```
## Without `for` loop - works
```{r}
datatable(cars)
g <- ggplot(cars) + geom_histogram(aes_string(x=names(cars)[1] ))
ggplotly(g)
```
## From inside the `for` loop - does not work (nothing is printed)
```{r}
for( col in 1:ncol(cars)) {
datatable(cars) # <-- does not work
print( datatable(cars) ) # <-- does not work either …Run Code Online (Sandbox Code Playgroud)