rstudio / pagedown

Paginate the HTML Output of R Markdown with CSS for Print
https://pagedown.rbind.io
Other
885 stars 129 forks source link

Ability to print ggplotly in for loop does not work with html_paged #232

Open andrew-fuller opened 3 years ago

andrew-fuller commented 3 years ago

Hi all,

I am working on producing a report that would ideally use plotly to generate plots and text and in a for loop. It seems like the pagedjs is interfering with the ability for this to work.

Here is a small reprex taken from here: https://stackoverflow.com/questions/60685631/using-ggplotly-and-dt-from-a-for-loop-in-rmarkdown

Any help with this issue would be greatly appreciated.

Does not render plots.

---
title: "Title of the report"
subtitle: "Subtitle of the report"
author: "Author Name"
date: "Date"
output: pagedown::html_paged
---

```{r setup, include=FALSE}
library(plotly); library(DT)
```

```{r, include=FALSE}
# Init Step to make sure that the dependencies are loaded
htmltools::tagList(datatable(cars))
htmltools::tagList(ggplotly(ggplot()))
```

```{r, results='asis'}
for( col in 1:ncol(cars)) {

  print(htmltools::tagList(datatable(cars)))

  g <- ggplot(cars) + geom_histogram(aes_string(x=names(cars)[col] ) )

  print(htmltools::tagList(ggplotly(g)))

}
```

Does render plots.

---
title: "Title of the report"
subtitle: "Subtitle of the report"
author: "Author Name"
date: "Date"
output: html_document
---

```{r setup, include=FALSE}
library(plotly); library(DT)
```

```{r, include=FALSE}
# Init Step to make sure that the dependencies are loaded
htmltools::tagList(datatable(cars))
htmltools::tagList(ggplotly(ggplot()))
```

```{r, results='asis'}
for( col in 1:ncol(cars)) {

  print(htmltools::tagList(datatable(cars)))

  g <- ggplot(cars) + geom_histogram(aes_string(x=names(cars)[col] ) )

  print(htmltools::tagList(ggplotly(g)))

}
```
RLesur commented 3 years ago

Hi @andrew-fuller,

Thanks a lot for this report!

datatable and ggplotly are HTML widgets and are not yet supported by pagedown (see #58). Despite we have a proposal to support them (see #87), it seems that even with #87, solving this use case is not straightforward.

I think #87 needs to be improved to support this case.

andrew-fuller commented 3 years ago

Thanks @RLesur !

Keep up the great work on Pagedown!