14.6 Shiny components

Tutorials are essentially Shiny documents, which we will introduce in Chapter 19. For that reason, you are free to use any interactive Shiny components in tutorials, not limited to exercises and quiz questions.

The Shiny UI components can be written in normal R code chunks. For the Shiny server logic code (rendering output), you need to add a chunk option context="server" to code chunks. For example:

```{r, echo=FALSE}
sliderInput("bins", "Number of bins:", 30, min = 1, max = 50)
plotOutput("distPlot")
```

```{r, context="server"}
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')
})
```

Again, since tutorials are Shiny applications, they can be deployed using the same methods mentioned in Section 19.2.