19.6 Delayed rendering

A Shiny document is typically rendered every time it is shown, and is not shown to the user until the rendering is complete. Consequently, a document that is large or contains expensive computations may take some time to load.

If your document contains interactive Shiny components that do not need to be rendered right away, you can wrap Shiny code in the rmarkdown::render_delayed() function. This function saves its argument until the document’s rendering is done and has been shown to the user, then evaluates it and injects it into the output document when the computation is finished.

Here is an example that demonstrates how render_delayed() works. The code enclosed within the render_delayed() call will execute only after the document has been loaded and displayed to the user:

```{r, echo = FALSE}
numericInput("rows", "How many cars?", 5)

    head(cars, input$rows)