RMarkdown Website Using Shiny Prerendered Documents

Is it possible to use rmarkdown's site generator to create a site consisting of several Shiny Prerendered documents? I have created a website consisting of several Rmd files using the shiny runtime, and I attempted to switch them to the shiny_prerendered runtime in order to take advantage of the improved performance provided by Shiny Prerendered documents. However, doing so causes site navigation to break, as the initial document is simply refreshed no matter which URL is visited on the site.

Looking at the source of rmarkdown::run(), this appears, at first glance, to be due to the differences in the way rmarkdown handles converting Shiny and Shiny Prerendered documents into Shiny Apps. That is, when rmarkdown::run() encounters a Shiny document, the generated Shiny App's server function creates a reactive expression for the rendered document, which updates whenever the file is changed. However, when rmarkdown::run() encounters a Shiny Prerendered document, it simply parses the file and produces a Shiny App from the contents of said file.

Furthermore, the Shiny Server documentation states

Particular Rmd files can be accessed by referencing their full path including the filename, e.g., http://myserver.org/mydocs/hello.Rmd .

However, this does not appear to be the case if the Rmd files use the shiny_prerendered runtime. In this case, the index.Rmd document is displayed no matter what URL is visited.

Is this a current limitation of Shiny Prerendered documents, or is there something that I am missing?

Thanks in advance for any help!


Thanks for the helpful clarification that you are using Shiny Server here!

Am I right in understanding that this worked as you expected when you used the shiny runtime?

What exactly is the behavior when you switch to shiny_prerendered? It sounds like:

  • Use a relative link re: ../some-other-page
  • when you click on the link, what does it do to your URL bar?
  • what if you change the URL bar manually to the link that you want?

It would also be helpful to have a simple example if possible of the layout / folder structure / code examples that you are using. That could lower the bar for someone in the community who wants to give this a try themselves and see if there is an easy way to assist / get things functional!

Hi @cole ,

I wasn't sure if I should use the RMarkdown label or the Shiny Server label for this topic. Let me know if you think that I should update it.

To answer your first question, yes, this works as expected when using the shiny runtime.

Unfortunately, I cannot share the code for the project I am working on, but I have created a repo containing two versions of a basic, demonstrative example: one using the shiny runtime, and one using the shiny-prerendered runtime.

I have also done my best to describe what I am trying to accomplish. What I describe hereafter can be seen either by opening one of the Rmd files in RStudio and clicking "Run Document" to trigger the start of a Shiny Server, or by copying the shiny_runtime and shiny_prerendered_runtime directories to an existing, deployed Shiny Server and navigating to the server in a browser.

Consider the simple website created in the repo linked to above, which consists of the following files:

β”œβ”€β”€ _site.yml
β”œβ”€β”€ index.Rmd
β”œβ”€β”€ inputs_and_outputs.Rmd
└── mpg.Rmd

As can be seen in _site.yml, page navigation occurs using a navbar, in which the href of the individual menu items target the associated Rmd files.

When using the shiny runtime, the website functions as expected. That is, clicking on a menu item in the navbar will cause the URL to update to http://<shiny-server>/<targeted-file>.Rmd, and the page to render.

However, when using the shiny-prerendered runtime, the website ceases functioning. That is, clicking on a menu item in the navbar will still cause the URL to update to http://<shiny-server>/<targeted-file>.Rmd, but instead of rendering the new page, the index.Rmd page will simply be refreshed. The same behavior occurs if the URL is manually entered, even without having first visited index.Rmd. I assume this is because of the way Shiny Server handles RMarkdown files; that is,

If a hosted directory does not include a server.R file, Shiny Server will look to see if it contains any .Rmd files. If so, Shiny Server will host that directory in "R Markdown" mode using rmarkdown::run .

Since rmarkdown::run() targets index.Rmd by default, this is the page that will remain displayed no matter which Rmd file is targeted in the URL.

Note that, in the example using the shiny_prerendered runtime, updating _site.yml to target the html files produced, instead of the Rmd files, does not affect the incorrect behavior in any way.

1 Like

Hi @hugo-pa!

First off, HUGE thank you for the github repo to reproduce the error!! It made it very quick for me to chase down.

This is a bug in rmarkdown (link to issue). The line of code below is returning static html from the original prerendered document. This is not reacting according to the route (req$PATH_INFO) being served.

Thank you for the reprex and issue!

- Barret


Hi @barret,

I had a feeling that the issue was related to the way that the shinyApp is produced for documents using the shiny_prerendered runtime, but didn't have time to take a close enough look to pinpoint the exact cause of the issue. Thank you very much for taking the time to do so and for opening an issue on GitHub!


This topic was automatically closed 21 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.

Is there anyone working on this issue? Just tried a similar process as described above and found it doesn’t work; the examples in github continue to demonstrate the problem (beautifully). It does somewhat restrict the use of Shiny.

The issue is still opened

Hopefully we will be able to work on it soon.

1 Like

This topic was automatically closed after 13 days. New replies are no longer allowed.