I am trying to embed a tutorial Rmd from the learnr
package into a full shiny app. However, learnr uses the shiny_prerendered
runtime, I cannot call it within my app. How do I get an interactive tutorial to run within my shiny app?
I have have three files right now: ui.R, server.R, and tutorial.Rmd.
My tutorial looks like this (one ` removed for formatting)
---
title: "my tutorial"
tutorial:
id: "com.example.tutorials.a-tutorial"
version: 1.0
output: learnr::tutorial
runtime: shiny_prerendered
---
``{r setup, include=FALSE}
library(learnr)
knitr::opts_chunk$set(echo = FALSE)
``
### Exercise Example
An R code question
``{r add-function, exercise=TRUE, exercise.lines = 5}
add <- function() {
}
``
### Quiz
R Quiz Question
``{r quiz}
quiz(
question("Question 1",
answer("wrong"),
answer("also wrong"),
answer("right", correct = TRUE),
answer("wrong again")
)
)
``
When I try rendering the output of this file from ui.R
like so:
ui <- tagList(
fluidPage(theme = shinytheme("cosmo")),
navbarPage(
"appTitle",
tabPanel("Embedding Tutorials?",
includeMarkdown("tutorial.Rmd")
),
)
)
It (properly, I believe) displays it as a regular old Rmd file, not an interactive tutorial.
I've also tried using rmarkdown::render("tutorial.Rmd")
which just renders the filepath to the html file generated by the Rmd (/Users/me/app/tutorial.html
).
When I try to render any tutorial using run_tutorial("hello", package="learnr")
, it (again, rightfully) gives the error
ERROR: Can't call
runApp()from within
runApp(). If your application code contains
runApp(), please remove it.
I've already discovered that I can create question chunks using the question()
function in learnr
using the following:
ui <- tagList(
fluidPage(theme = shinytheme("cosmo")),
navbarPage(
"appTitle",
tabPanel("Tutorial",
quiz(
question("Quiz question",
answer("1"),
answer("2"),
answer("3", correct = TRUE),
answer("4"),
allow_retry = TRUE
)
),
)
)
But this does not allow the functionality of creating R code chunks that can be run within the app.
What I want is a fully interactive learnr tutorial that can be rendered from within a ui.R
file for a shiny app. Is this possible?