0

I want to have more html in exams generated by exams2html()and exams2moodle. But if I try e.g. to include a ploty plot by

```
library(ggplot2)
library(plotly)
ggplotly(
  ggplot(iris, aes(Sepal.Length, Petal.Length)) + geom_jitter()
)
```

exams2html() contains only a image generated by {webshot}(I think).

Is it possible to specify some knitr options in the exams-workflow which solve this problem?

EDIT:

Here is a minimal-example for integrating plotly-plots into .Rmd files:

---
title: "Plotly to html within RMarkdown"
output: html_document
---


## Minimal Example

You can integrate `plotly` plots seamlessly into .html-files generated via knitr from .Rmd:

```{r}
library(plotly)
plot_ly(economics, x = ~date, y = ~unemploy / pop)
```
sammerk
  • 1,143
  • 1
  • 9
  • 23
  • It will certainly be possible to get this to cooperate with `exams2html()`. The essential idea would be to (1) set up a template that contains the header with all the required `.css` and `.js` libraries and (2) capture the HTML output from `ggplotly()` and embed it into the exercise. Possibly some `knitr` features can be exploited for this - I'm not sure because I haven't used `plotly` much. With a more worked example I might be able to say more. – Achim Zeileis Nov 02 '17 at 23:19
  • Whether Moodle would be happy about such content I cannot say. Usually we import HTML content into Moodle without any header and Moodle uses the style it has been configured to use. I could imagine that Moodle installations run by institutions such as universities would not let you embed `.js` or `.css` because this could also be abused fairly easily. However, if you have control over the Moodle installation your chances are probably better. But I haven't tried anything like this and also haven't looked at the Moodle manuals. – Achim Zeileis Nov 02 '17 at 23:22
  • I just had another look at this but so far failed to embed `plotly` in plain `.Rmd`/`knitr` documents (without the `exams` package involved). I tried to follow the advice at https://plotlyblog.tumblr.com/post/106630252117/plot-with-ggplot2-and-plotly-within-knitr-reports and https://plot.ly/r/knitr/#embedding-plotly-graphs-in-rmd-files but didn't succeed yet. It might help to see a complete R/Markdown file (like the `plotly-report.Rmd` that is mentioned but apparently not shared). If you could post such a file and I could try to have another stab... – Achim Zeileis Nov 03 '17 at 19:19
  • @AchimZeileis: thank's for your effort so far! I'm not sure about the didactictal benefit of using plotly plots. Thus far I loved plotly plots for it's opportunity assessing exact values (e.g. IQR from boxplots) via mouse over effect ... I added a minimal example for plotly-plots in .Rmd -->> .html – sammerk Nov 12 '17 at 11:03
  • Thanks for the example! When I run that through `knitr::knit()` I obtain an `.md` file that embeds a static `.png` snapshot of the plotly figure. Only when I use `rmarkdown::render()` the dynamic plotly figure is used. I'm not sure what I need to do to obtain the `knitr` output before calling `pandoc`. This would make it easier to embed it into the `exams` workflow. – Achim Zeileis Nov 12 '17 at 20:59

0 Answers0