## 19.2 Deployment

Shiny documents must be supported by a live R session running behind the scenes. When you run a Shiny document locally, it uses your local R session. Usually only you can see and interact with the document. If you want to share the document with people who do not have R installed, or do not want to run the document locally, you will have to deploy the document on a server, and share the URL of the document. Then other people only need a web browser to visit your document.

There are two ways to deploy a Shiny document. You can either use a hosted service provided by RStudio, or set up your own server. The first way is technically easier, but sometimes you may not be allowed to use an external hosted service, so you have to install the required software (Shiny Server or RStudio Connect) on your own server to deploy the Shiny documents.

### 19.2.1 ShinyApps.io

You can publish Shiny documents to the ShinyApps (https://shinyapps.io) hosted service. To do this you, should ensure that you have:

1. An account on ShinyApps (use the signup form to request an account).

2. A latest version of the rsconnect R package. You can install this as follows:

install.packages("rsconnect")

You can then deploy an interactive Shiny document in the same way that you currently deploy normal Shiny applications. From the working directory containing the document(s), just execute:

rsconnect::deployApp()

If you are using RStudio, you can also use the Publish button available at the top-right of the window when running a Shiny document (see Figure 19.4).

If there is a file named index.Rmd in the directory, it will be served as the default document for that directory, otherwise an explicit path to the Rmd file should be specified in the URL if you want to visit this Rmd document. For example, the URL for index.Rmd deployed to ShinyApps may be of the form https://example.shinyapps.io/appName/, and the URL for test.Rmd may be of the form https://example.shinyapps.io/appName/test.Rmd.

### 19.2.2 Shiny Server / RStudio Connect

Both Shiny Server (https://www.rstudio.com/products/shiny/shiny-server/) and RStudio Connect (https://www.rstudio.com/products/connect/) can be used to publish Shiny documents. They require knowledge about Linux. Installing and configuring them should normally be a task for your system administrator if you are not familiar with Linux or do not have the privilege.