learnr package for teaching Shiny…is it possible?

I am enjoying using the learnr and grader packages for R. I have managed to incorporate some shiny elements, very nice!

However, i would like to include exercises where learners can write, check and submit answers for shiny based questions. However, the run code function in an exercise doesn't do anything (i get shiny window saying Shiny app not supported in static R Markdown documents), so i'm assuming it will not work or i have missed something?

this is a sample of the exercise code;

title: "Programming basics"
output:
  learnr::tutorial:
    progressive: true
    allow_skip: true
runtime: shiny_prerendered

```{r ex_shiny_1, exercise=TRUE}
library(shiny)
ui <- fluidPage(
  titlePanel("My First App"),
  sidebarLayout(
    sidebarPanel("inputs will go here"),
    mainPanel("outputs will go here")
  )
)

server <- function(input, output) {}

shinyApp(ui = ui, server = server)

I know i can uses quizes within learnr, but i would really like the users to see their shiny code running without having to move from the tutorial to RStudio IDE.

Ive managed to include shiny elements in the tutorial using something similar to and work really well;

sliderInput("bins", "Number of bins:", 30, min = 1, max = 50)
plotOutput("distPlot")
output$distPlot = renderPlot({
  x = faithful[, 2]  # Old Faithful Geyser data
  bins = seq(min(x), max(x), length.out = input$bins + 1)
  hist(x, breaks = bins, col = 'darkgray', border = 'white')
})

Thanks in advance!

@SiobhanKeleher (I'm a current learnr maintainer.) You have not missed anything. As you've found, currently the exercises are evaluated within a static knitr document.

Theoretically, it should be possible to change this to a runtime: shiny. I'll have to change with a couple people about safety and implementation as this would create a new continuous connection for each shiny based exercise.

This makes sense and I support moving towards this.

Issue submitted: https://github.com/rstudio/learnr/issues/215

Amazing thanks! Wasn't sure if it was me being an idiot (quite usual). Loving the package so this included would make it totalllly amazing!

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.