13 Deploy Your Application
Your deploys should be as boring, straightforward, and stress-free as possible.
How to Deploy Software - Zach Holman (https://zachholman.com/posts/deploying-software)
Once your app is built, you are ready to deploy it! In other words, your software is now ready to be used by other users. There are two main ways to share your application and make it available to others: by creating a package and making it installable, or by sending it to a remote server. We will see in this part how you can do that using golem (Fay, Guyader, Rochette, et al. 2023).
13.1 Before deployment checklist
Here is a quick checklist of things to think about once your application is ready, and before sending it to production:
13.3 Deploying apps with {golem}
The other way to make your application available to others is by sending it to a remote server that can serve shiny applications. In other words, instead of having to install the application on their machines, they can crack open a web browser and navigate to the URL where the application is deployed. Deploying to a server is the solution of choice when you want to make your application available to a wide public: on a server, visitors do not have to have R installed on their computer, they do not have to install a package or launch it; they can just browse the application like any other web application. This solution is also a common choice in companies that have strict security requirements: the IT team might not be willing to let everyone install software on their machine, and sharing an application on a server allows them more control over who can access the application. For example, deploying on a server allows you to use a proxy, and to filter by IP: then, only a subset of people can have access to the application.
When using golem, you can open the dev/03_deploy.R
and find the functions for server deployment.
At the time of writing this book, there are two main ways to deploy a shiny app on a server:
- RStudio’s solutions
- A Docker-based solution
13.3.1 RStudio environments
RStudio proposes three services to deploy shiny application:
shinyapps.io
, an on-premises solution, can serve shiny application (freemium).Shiny Server
is a software you have to install on your own server, and can be used to deploy multiple applications (you can find either an open source or a professional edition).RStudio Connect
is a server-based solution that can deploy shiny applications andMarkdown
documents (and other kinds of content), and serves them as ordinary websites.
Each of these platforms has its own function to create an app.R
file that is to be used as a launch script of each platform.
These app.R
files call a pkgload::load_all()
function, that will mimic the launch of your package, and then call the run_app()
function from your packaged app.
Note that if you need to configure the way your app is launched on these platforms (for example, if you need to pass arguments to the run_app()
function), you will have to edit this file.
Note that when using these functions, you will be able to use the “One click deploy” for these platforms: on the top right of these app.R
, use the Blue Button to deploy to a server.
Another way to deploy your golem-based app to shiny server and to Connect is to link these two software to a local repository (for example, an RStudio Package Manager), and then to only use mypackage::run_app()
to the app.R
.
13.3.2 Docker
Docker is an open source software used to build and deploy applications in containers. Docker has become a core solution in the DevOps world and a lot of server solutions are based on it. See Part 5, “Strengthen”, for a more complete introduction to Docker.
You will find the function for creating a Dockerfile
for your golem app inside the 03_deploy.R
file, which contains a series of 3 functions:
The first function creates a “generic” Dockerfile
, in the sense that it is not specific to any platform, and would work out of the box for your local machine.
The second one is meant for {shiny}
Proxy, an open source solution for deploying containerized shiny applications, and the third is for Heroku, an online service that can serve containerized applications (not specific to shiny).
Other platforms can run Docker containers, notably AWS and Google Cloud Engine. At the time of writing these lines, golem does not provide support for these environments, but that is on the to-do list!
Note that the Dockerfile
creation in golem tries to replicate your local environment as precisely as possible, notably by matching your R version, and the version of the packages you have installed on your machine.
System requirements are also added when they are found on the sysreqs service from r-hub.
Otherwise you might have to add them manually.