Support

Static Content on RStudio Connect

Follow

RStudio Connect is primarily used for hosting Shiny applications, R Markdown documents, plumber APIs, and TensorFlow models.  However, RStudio Connect can also be used to serve static content including HTML sites and PDFs. Hosting static HTML is useful for hosting blogdown sites, pkgdown sites, bookdown books, or even custom landing pages written in HTML. Hosting static PDFs is useful if you want to deploy PDF documents that were not generated from R Markdown but still support an analysis.

Static content can be deployed using the rsconnect package. For example, if you have HTML content in a directory structure similar to:

.
|__ index.html
|__ css
|__ styles.css
|__ images
|__ image.png

 

Use the following command to deploy the site to RStudio Connect:

rsconnect::deployApp(".",                       # the directory containing the content
appFiles = list.files(".", recursive = TRUE), # the list of files to include as dependencies (all of them)
appPrimaryDoc = "index.html", # the primary file
appName = "my-site", # name of the endpoint (unique to your account on Connect)
appTitle = "My Site", # display name for the content
account = <connect-user-name>, # your Connect username
server = <connect-server> # the Connect server, see rsconnect::accounts()
)

For pkgdown you would run this command inside the docs subdirectory. For blogdown this command should be used in the public directory created after rendering the site.

RStudio Connect will always host the html content at a non-root URL. For example, if you deploy a blogdown site, Connect will serve the index of the site at a URL like connect.example.com/mysite/ NOT connect.example.com. This can cause problems with some HTML sites. In blogdown, for instance, consider setting relativeURLs = true in config.yml.

To deploy single page content like a PDF you can alternatively use rsconnect::deployDoc which takes similar arguments.

The preferred method for publishing bookdown books is bookdown::publish_book which accepts an account, a server, and an optional render argument which specifies where the book should be rendered. If you've already rendered the book locally, use render = "none".

A related function is rsconnect::deploySite. This function is specific to deploying R Markdown websites.

Comments