Shiny on ECS

[This article was first published on R | datawookie, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

A recipe for setting up a simple Shiny app on ECS.

Docker Image

? If you want to simply use my Docker image for testing, then you can skip this section and go straight to deploying.

Since this is for illustration purposes, I’m going to keep the app itself super simple, just using a slightly modified version of the “Old Faithful Geyser Data” template app, faithful.R.

We need to wrap this up in a Docker image. Here’s the Dockerfile:

FROM rocker/shiny:4.1.0

# Install R packages.
#
RUN install2.r -e dplyr

# Remove boilerplate.
#
RUN rm -rf /srv/shiny-server/

# Copy app.
#
COPY faithful.R /srv/shiny-server/app.R

Just to be sure that this works, we’ll build and run it locally. First build the image, giving it the name faithful.

docker build -t faithful .

Now run it. You should be able to access the app on http://127.0.0.1:3838/.

docker run --rm --name faithful -p 3838:3838 faithful

Once you’ve established that this runs locally, we can move onto deploying on ECS. If it doesn’t work locally, then ECS is going to be a whole world of pain.

There’s one final step, which is putting the image into a registry accessible from ECS.

Deploying on ECS

These are the high level steps involved in deploying a Shiny app on ECS. Click through to the additional resources to see the details. Once you’ve been through this process once it should become somewhat intuitive, but the first time around it can be mysterious and challenging.

  1. Create an ECS cluster. See this post.
  2. Define an ECS task. See this post. Some specifics:
    • task name: faithful
    • container name: faithful
    • image: datawookie/faithful:latest (? Feel free to use this for testing!)
    • port mappings: 3838
  3. Run the ECS task. See this post. Some specifics:
    • security group: inbound traffic on port 3838 (see this post)

It should take a short while for the task to start running.

Once th task is RUNNING, click on the task ID (in this case 4859f33811ed4f06b6f7944234b48a3c) to see the task details.

You’ll see that there’s a public IP address listed (in this case 18.209.221.45).

Open that IP address in your browser, specifying port 3838.

So that’s how you get a basic Shiny app up and running on ECS. It’s functional but it’s not the end of the road. Next steps:

  • Set the task up to run as a persistent service.
  • Add a load balancer.
  • Add an SSL certificate so that the app is accessible via HTTPS.

If you get stuck, have questions or comments, ping me.

To leave a comment for the author, please follow the link and comment on their blog: R | datawookie.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)