-
Notifications
You must be signed in to change notification settings - Fork 240
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
Plotly not working ? #744
Comments
Try including a plotly plot in the static portion of your content. We remove web dependencies from code rendered in exercises since it would allow users to add arbitrary web deps to your main tutorial. If you include the plotly dependencies in your tutorial, by adding a plotly plot to the static part, then exercise results should work as expected. If not, feel free to follow up. |
Ok so basically is impossible for students to input the code and see the results by themselves ? |
No it's very possible but you have to anticipate the usage. |
I don't understand, how can you do it then ? |
Here's an example. If you show students a plotly plot in your tutorial, the dependencies are loaded and available when their code returns a plotly plot. ---
title: "Tutorial"
output: learnr::tutorial
runtime: shiny_prerendered
---
```{r setup, include=FALSE}
library(learnr)
library(hrbrthemes) # for general style
library(plotly) # to make the chart interactive
library(tidyverse)
library(gapminder)
knitr::opts_chunk$set(echo = FALSE)
```
## Topic 1
Try to recreate this plot, but better looking.
```{r preview, warning = FALSE}
p <- gapminder %>%
filter(year == "1952" & country != "Kuwait") %>%
ggplot(aes(x = gdpPercap, y = lifeExp, fill = continent)) +
geom_point(alpha = 0.7, stroke = "white", shape = 21)
ggplotly(p)
```
### Exercise
```{r interactive, exercise = TRUE, exercise.eval = FALSE, warning=FALSE}
p <- gapminder %>%
filter(year == "1952" & country != "Kuwait") %>%
arrange(desc(pop)) %>%
ggplot(aes(x = gdpPercap, y = lifeExp, fill = continent, size = pop)) +
geom_point(alpha = 0.7, stroke = "white", shape = 21) +
theme_ipsum()
ggplotly(p)
```
```{r interactive-solution, warning=FALSE}
p <- gapminder %>%
filter(year == "1952" & country != "Kuwait") %>%
arrange(desc(pop)) %>%
ggplot(aes(x = gdpPercap, y = lifeExp, fill = continent, size = pop)) +
geom_point(alpha = 0.7, stroke = "white", shape = 21) +
theme_ipsum()
ggplotly(p)
``` |
@munoztd0 I'm sorry, I was misremembering how html dependencies are handled in learnr. We do filter out some web dependencies – in particular to limit dependencies to only those served by packages — but your example should have worked without modifications. I have a fix in #747 that I will merge shortly. |
Can anyone explain why basic ggplotly object doesn't render on learnR tutorials ?
Or do I have to to something special ?
Code:
The text was updated successfully, but these errors were encountered: