How to deploy learnr-tutorials to shinyapps.io with rsconnect

R
shiny
shinyapps.io
Autor:in

Johannes Titz

Veröffentlichungsdatum

14. April 2022

The new term just started and I wanted to update my interactive r course (https://rlernen.de), which is based on learnr. I really love learnr because it produces a beautiful website without much effort and has all the features I need to make a good R course. There are a couple of small things that I learned about learnr, of which I will share one today: How do you upload a learnr Rmd file to shinayapps.io?

Of course you can use the Publish-Button in RStudio, but this is somewhat inconvenient, especially if you have several tutorials in a single project. In the background the Publish-Button uses rsconnect, so you might think that this should work:

rsconnect::deployApp(appName = "appname", account="youraccount",
                     appFiles = c("your.Rmd"))

But this only works for actual shiny apps. What we have is an Rmd document which uses shiny, so the correct command is:

rsconnect::deployDoc(appName = "appname", account="youraccount",
                     doc = c("your.Rmd"))

Do not forget to change appFiles to doc. Also, do not use appDir, appFiles and appPrimaryDoc, they are automatically generated from the Rmd.

I wonder why this is not explained in the learnr documentation. I guess it is common knowledge as it is explained on the shiny prerendered documents site: https://rmarkdown.rstudio.com/authoring_shiny_prerendered.HTML#Deployment

Anyway, the command is quite useful and more flexibel than the Publish-Button.