Deploy a Shiny web application online for free

Give access to your products using 3 R commands

Release data science work through online applications creates tangible value for your customers. In this article, I provide a step by step tutorial to deploy a Shiny application using, a cloud service developed by RStudio which offers a free pricing option.

The 3 most common cloud services used by data science teams are Amazon Web Services (AWS), Google Cloud Platform (GCP) and Microsoft Azure (Azure).

Leveraging Docker container technology, these platforms may provide entry points to machine learning models or analytics web applications. These tools are then accessible online.

Amazon, Google and Microsoft offer free trials, which simply put, consist in a given amount of money to test the platform for a period of 1 to 12 months. In the end of the trial, you will have to upgrade to a paid account to keep using the service.

However, even in the context of a free trial, there is a risk of receiving a huge bill at the end of the month. It is not always possible to set a limit to services usage, which would be convenient to avoid exceeding the free trial money. Moreover, at the end of the trial, your deployed applications will be out-of-service if you don’t upgrade to a paid account.

Not really suitable for someone trying to monkey with Shiny web applications…

As the goal here is just to release a Shiny application online, here’s a very simple solution involving $0, where exceeding usage limit is not possible: by RStudio

The free option offers 5 applications and 25 hours of monthly usage. No credit card required to sign up, and a service that stops whenever usage limit is reached. In my opinion, this is a really good option to safely start deploying Shiny applications online.

Wait… you do not have any Shiny application yet? No worries, 24 lines of code are enough to start building your own. 🚀

The sign up process is straight forward: you need to create an account and define your server’s root URL. Don’t forget to verify your email address… and that’s it!

Once you landed on your dashboard, you find 3 steps to deploy your Shiny web application online, each step being a single R command I discuss below.

Step 1 / 3

To release your application on, you need rsconnect package: this is a programmatic interface for deployments developed by the RStudio team. It contains functions to deploy a Shiny web application directly from the R console!

Need a quick reminder on how to install a R package? Check out the first lines of my previous article!

Step 2 / 3

Authorize your computer to perform deployment operations on your behalf using rsconnect::setAccountInfo command.

Basically, you must provide a token and a secret, available on your dashboard: just click the button Copy to clipboard and paste the result in your R console.

Step 3 / 3

Now it is time to deploy your Shiny application using rsconnect::deployApp. You may give any path as a parameter of this function, as long as it leads to the app.R file of your web application. Mine is located in the current directory:

Before testing the app, let’s have a look at the dashboard on the application is now online and running!

A click on the name of the application leads to a more detailed dashboard:

There are a lot of functionalities here and some of them are unknown to me (Size: large?). This dashboard deserve an entire article so stay tuned. 😉

Now let us have a look at our deployed application, assuming you started from the one provided, after clicking on its URL…

Oops. Fortunately the error is clear: runApp command should be remove when the application is deployed.

However keeping this command to run the Shiny application in RStudio viewer pan is really convenient. RStudio software engineer Yihui Xie suggests this line of code to detect whether the Shiny application runs locally or on the server.

It basically detects if the environment variable SHINY_PORT is set, which is the case when the application is running on a Shiny Server instance. Here we create a logical variable to decide if runApp should be called or not in app.R file.

You may find the full project on my Github account

Now after deploying again using the previous rsconnect command, the previous version of our application is erased on the platform. At the end of the process, let us go back on our dashboard, and click the application’s URL:

Final words

You are now able to build and deploy a Shiny application online for free, which is an opportunity for you to share some work with anyone having the URL of your application. I hope you enjoyed this article, feel free to share some links to your applications 😉 feedback is welcome!

🇫🇷 Data scientist

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store