Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shiny Server on AWS Elastic Beanstalk with Docker

How is it possible to deploy a shiny app via Shiny Server in a Docker container deployed to Elastic Beanstalk?

Theoretically it is possible to run R/Shiny (Server) on AWS Elastic Beanstalk with Docker containters. Unfortunately, I couldn't see any tutorial on this topic and my attempts failed miserably.

It is possible to deploy Shiny Server on EC2 instances with autoscaling (been there, done that) so EB shouldn't be to much of a problem. But again, my experience and knowledge is limited.

like image 349
berkorbay Avatar asked Sep 02 '25 06:09

berkorbay


2 Answers

Here's a sketch of the full procedure, including installing additional R packages.

Put your shiny apps in a directory called apps. Multiple apps can live in multiple subdirectories of apps.

Make a file called Dockerfile.base with the following contents.

FROM rocker/shiny
# Install more R packages like this:
RUN . /etc/environment && R -e "install.packages(c('ROCR', 'gbm'), repos='$MRAN')"

Build it locally and push to AWS ECR. Follow AWS's instructions but here's a sketch.

# region="us-west-1"
# aws_account_id=123456789
aws ecr get-login-password --region $region | docker login --username AWS --password-stdin ${aws_account_id}.dkr.ecr.${region}.amazonaws.com
docker build -t rshiny-base Dockerfile.base
docker tag rshiny-base:latest ${aws_account_id}.dkr.ecr.${region}.amazonaws.com/rshiny-base:latest
docker push ${aws_account_id}.dkr.ecr.${region}.amazonaws.com/rshiny-base:latest

Create a new Dockerfile with the following contents. Note that it is copying your apps into the image.

FROM <aws_account_id>.dkr.ecr.<region>.amazonaws.com/rshiny-base
USER shiny
COPY apps /srv/shiny-server
EXPOSE 3838
CMD ["/usr/bin/shiny-server.sh"]

Git-commit, create an Elastic Beanstalk app, and deploy. Here's a sketch:

eb init
eb create shiny

I wrote the full procedure up in a blog post at https://www.highonscience.com/blog/2021/06/02/shiny-apps-elastic-beanstalk/.

like image 118
Will High Avatar answered Sep 04 '25 19:09

Will High


It appears that doing it was straightforward. Here is a minimal Dockerfile for the example Shiny Server run.

FROM rocker/shiny:3.6.3
USER shiny
EXPOSE 3838
CMD ["/usr/bin/shiny-server.sh"]

You can directly upload from ElasticBeanstalk interface.

Here are two very important basic mistakes that may be trouble in EB deployments

  • Whole installation from Dockerfile should not exceed 300 seconds (I had this error because of R tidyverse installations).
  • If you upload a folder, make sure there is no parent folder to your files (esp. Dockerfile).
like image 36
berkorbay Avatar answered Sep 04 '25 18:09

berkorbay