Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
andrew-fuller opened this issue Jul 13, 2021 · 2 comments
Open
Assignees

Comments

@andrew-fuller
Copy link

andrew-fuller commented Jul 13, 2021

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
Copy link
Collaborator

RLesur commented Jul 18, 2021

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 RLesur self-assigned this Jul 18, 2021
@andrew-fuller andrew-fuller reopened this Jul 19, 2021
@andrew-fuller
Copy link
Author

Thanks @RLesur !

Keep up the great work on Pagedown!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants