pagedown icon indicating copy to clipboard operation
pagedown copied to clipboard

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

Open andrew-fuller opened this issue 2 years ago • 2 comments

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)))

}
```

andrew-fuller avatar Jul 13 '21 01:07 andrew-fuller

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.

RLesur avatar Jul 18 '21 15:07 RLesur

Thanks @RLesur !

Keep up the great work on Pagedown!

andrew-fuller avatar Jul 19 '21 06:07 andrew-fuller