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

ggplotly() not working. #105

Closed
fyuniv opened this issue Sep 13, 2023 · 1 comment
Closed

ggplotly() not working. #105

fyuniv opened this issue Sep 13, 2023 · 1 comment
Assignees

Comments

@fyuniv
Copy link

fyuniv commented Sep 13, 2023

When trying to create an interactive box plot, I noticed that ggplotly() does not work as expected. No image was produced/embedded in the output html file. The following is an example.

---
title: "Testing `plotly`"
output:
  markdown::html_format
---

```{r setup, echo=FALSE, warning=FALSE}
library(ggplot2)
library(plotly, warn.conflicts = FALSE)
library(htmlwidgets)
```

## Box Plot Without `ggploty()`

```{r echo=FALSE, results = 'asis', fig.width=12, fig.asp=0.4, fig.cap="ggplotly not working", fig.align='center'} 

boxplot<-ggplot(mtcars, aes(x=as.factor(cyl), y=mpg)) + 
    geom_boxplot(fill="royalblue") + 
    xlab("cyl")

boxplot
```

## Box Plot With `ggploty()`

```{r echo=FALSE, results = 'asis', fig.width=12, fig.asp=0.4, fig.cap="Without apply ggploty", fig.align='center'} 
ggplotly(boxplot)
saveWidget(ggplotly(boxplot), file = "plotlyboxplot.html")
```

## ggplotly as an Iframe

```{r echo=FALSE, results = 'asis', fig.width=12, fig.asp=0.4, fig.cap="Without apply ggploty", fig.align='center'} 
saveWidget(ggplotly(boxplot), file = "plotlyboxplot.html")
knitr::include_url("plotlyboxplot.html")
```

This is not a big issue and can be resolved. But it will be more convenient to be able to embed directly interactive images produced by the ggplotly() function.

@yihui yihui closed this as completed in 1b80096 Sep 13, 2023
@yihui
Copy link
Member

yihui commented Sep 13, 2023

The lack of support for HTML Widgets was documented in the intro vignette: https://cran.r-project.org/web/packages/markdown/vignettes/intro.html (in the section "Comparison to Pandoc")

However, I knew it was possible to support them and just experimented for a while. They should render now. You can install the development version via

remotes::install_github('rstudio/markdown')

Or wait for an hour or two and

install.packages('markdown', repos = 'https://rstudio.r-universe.dev')

Make sure packageVersion('markdown') >= '1.8.3') after installation.

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

No branches or pull requests

2 participants