An example how to show an HTML widget from the leaflet package.
Adapt the working directory below and run the setup chunk in RStudio. This creates the problem set files and the sample solution from this solution file.
library(RTutor) setwd("D:/libraries/RTutor/RTutor/inst/examples") ps.name = "HtmlWidgetExample"; sol.file = paste0(ps.name,"_sol.Rmd") libs = c("leaflet","magrittr","network3d") # Important add the parameter addons="quiz" ! create.ps(sol.file=sol.file, ps.name=ps.name, libs=libs, addons="quiz") show.ps(ps.name) stop()
Load libraries so that knit HTML also works
library(yaml) library(magrittr) library(leaflet)
Check to see an interactive leaflet centered on the department of Mathematics and Economics at Ulm University. The place where RTutor has been created.
To show an html widget output, you must add the chunk option output="htmlwidget"
. Further you must set the option widget
to the package of the HtmlWidget you want to show, here it is leaflet
.
#< task_notest SFmap <- leaflet() %>% addTiles() %>% setView(9.9620289,48.4251394, zoom = 11) %>% addMarkers(9.963614702355699,48.42517242865929, popup = 'RTutor was created here at Ulm University') SFmap #>
Here you can see what else you can do with the great leaflet packages:
http://rstudio.github.io/leaflet/
Here is a list of some other htmlwidgets, which now can also be used with RTutor:
http://www.htmlwidgets.org/
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.