Deploy your ShinyApp with Docker instead of

Jun 7, 2018 · 4 minute read ShinyApp Docker

A couple of months ago, I wrote a blog post on how to select the best linear regression model (for univariate models). In addition to the post, I wrote a small ShinyApp to let users practice the concept behind it:

Before I published the blog post, I thought about how and where to deploy this app?.

As the app is just for educational purposes it does not contain sensitive data. So seemed to be a good choice.

But soon after publishing, the limit of 25 active hours became a bottleneck. I thought that 25 hours a month is not a lot and will be reached sooner or later. But it did already after a couple of days…

A temporary upgrade to the Starter plan with 100 active hours allowed more traffic in the short-run but was not a permanent solution. So the question arose whether to upgrade to the basic plan with 500 active hours (for 39$ /month) or to deploy the app somewhere else.

Spending 39$ /month just for the infrastructure of this app seemed too much. So what options are there and why is it a good idea to use Docker?

Why not using ShinyServer on a dedicated server?


With you get access to cloud resources that have ShinyServer installed. However, is a managed environment with all its pros and cons. What you can use instead, is a dedicated server running ShinyServer alone. This gives you some freedom, but it also imposes costs:


  • There is no limit on active application hours. If the instance is running 247, users can always access your ShinyApp.
  • You can determine the performance of the server. Chose an instance with more CPU, RAM, and SSD storage to boost performance.
  • By setting up a virtual private network, you can restrict access (e.g. only allow access to users from a specific company by setting up an IP address filter)
  • You can run your application on your own infrastructure (this might be relevant if you work with sensitive data)
  • And finally, hosting can become more affordable. At DigitalOcean, for example, you can get a small instance from 5$ /month. Compared to this can decrease recurring costs a lot.


  • Setting up a server, and installing all dependencies will take more time than signing up for
  • Scaling your app can become tedious as you need to set up each server individually
  • You need to make sure that your app is running in the same way as it does on your local machine (DevOps)
  • Monitoring your app and server infrastructure will require additional tools
  • And finally, you need to take care of updates and security measurements. As is a managed service, they take care of the infrastructure updates, support, and security measurements. When you set up your own infrastructure, however, you need to take care of it.

Use ShinyServer with Docker

In my opinion, it is a better idea to use a Docker container with ShinyServer inside.

ShinyApp as Docker Image Container

Within the Docker container, you install R, ShinyServer, all packages that you need and add the ShinyApp. Once configured, you can deploy this Docker container on any web instance.


  • Once configured, you can run the Docker container on every instance you like.
  • So when migrating to a new server, you do not have to set up a server with Shiny again. Just install Docker, upload the Docker Image and start it.
  • If you expect a high demand (e.g. after releasing your ShinyApp, during marketing campaigns etc.) you can easily fire up a new instance, add a load balancer and scale your ShinyApp.
  • When setting up right, updates of R, Shiny or R packages will not affect future operations. By creating a Docker Image, you make sure that your app is reproducible.
  • Finally, you minimize DevOps problems as your ShinyApp runs exactly in production and on your colleague’s machines as it does on your local machine.


  • You need to take care of updates and security measurements nevertheless.


So this is what I could achieve by switching from to an instance running Docker:

  • There is no shortage of active hours anymore. The app runs 247, and users can always access it and stay as long as they like.
  • I brought down costs to 5$ /month.
  • The app runs significantly faster as there are more CPU and RAM available (even on the smallest instance at DigitalOcean).
  • The app scalable and can be deployed on any machine (PC, Mac, Linux) that has Docker installed.