How to deploy a Shiny app on AWS — Part 1
Recently, a client asked me to build an app with R Shiny. This app was supposed to be used to visualized plenty of indicators and also to interact with the data.
Rather basic for a Shiny app.
So I did my magic, created the dashboard, and the client was super happy!
Except… when he asked me to deploy it on his servers.
That’s when things got complicated.
As a data scientist, any R script has become a piece of cake. And since Shiny is getting more and more traction, I get more and more clients who ask me for automatic reporting dashboards where the users can visualize the data and interact with it.
But the problem is when we need to host the app.
I need a server, I need to configure it, update it, administrate it, and… well, it’s just not my job.
The “stupid” method
The first time I faced the issue, our team and I decided for a completely different solution.
We had no idea how to setup a server, nor the skills to do it anyway, so… we had to find another way.
It’s not pretty.
We installed R and the Shiny app on each individual computer for each user.
That’s what we did.
Every time we wanted to give access to a new user, we had to go to him, install R, the packages, everything, create a shortcut written in BATCH…
When you think about it, that’s kind of creative!
But also incredibly stupid…
- First, we still needed a way to share the data
- Then, it takes forever to install the app for each user. Such a waste of time!
- And, to maintain the app, build new features and deploy updates, it’s just hell.
But we had no choice.
Not the skills. And no help from the IT department.
Today, I know there exists a wayyy better solution.
The “smart” method
- Create a server in the cloud
- Send the app there
Ok, ok… I may be oversimplifying it just to make a point.
At first at least, it’s not that easy.
But once you know how to do it, you can make it work in half an hour.
And today, with this series of articles, my goal is to teach you exactly how to host a Shiny app on a server.
So, where to start?
First, we’ll use AWS.
AWS are the Amazon Web Services, i.e. all the services from Amazon in the cloud.
Of course, you could use other services, such as Azure from Microsoft, Digital Ocean, Rackspace, etc.
But I only know AWS, so that’s what we’ll use.
Important point to note: When you create a new account on AWS, you have free access to some services for a whole year.
Hence, everything we’ll do in these articles is potentially free.
The benefits of this smart method are:
- You can deploy the app without moving from your chair and give your client access.
- It’s easy to maintain and update, once everything is set up.
- You can easily change the server capabilities (for example if you suddenly need to handle big data queries) for a more powerful machine.
- You can add layers of security and restrict access to the app.
What should you expect?
My goal is to create reference articles, so that every time you need to deploy a Shiny app on AWS, you can come back here and find the solution.
Until you don’t need to come back anymore.
But I know from experience it’s easy to forget. So don’t hesitate to come back when you need.
I will explain each step with plenty of details, screenshots, drawings, maybe even videos!
- Create a Shiny app
- Create an AWS server
- Install R and R Shiny on your new server
- Deploy the app on the server
These steps are enough to get started!
But if you want to go further, I have created these new extra steps:
- Extra: Create a domain name to have a nice URL
- Extra: Secure your app with HTTPS
- Extra: Protect your app with a password
And then we’ll be good!
Let’s start right away with step 1: Create a shiny app
Actually, it’s not exactly the goal of this article to teach you the Shiny framework. So instead of spending time on that, let’s use an already existing app.
I chose the movie explorer from the Shiny gallery:
And I created a Github repo so that you can clone it easily: https://github.com/Huitziii/movie-explorer
Note that you’ll need git and a console for this tutorial. You can download git here: https://git-scm.com/downloads
Ok, now we’re ready!
To continue to the next step, click here:
Originally published at www.charlesbordet.com on August 21, 2018.