相关疑难解决方法(0)

在 Rmarkdown 的 for 循环中使用 ggplotly 和 DT

是否可以从循环或函数内部使用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)

r r-markdown dt ggplotly r-glue

3
推荐指数
1
解决办法
615
查看次数

标签 统计

dt ×1

ggplotly ×1

r ×1

r-glue ×1

r-markdown ×1