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:
Click on the image to open the app. The app allows users to estimate various linear models for a couple of datasets and demonstrates how specific selection criteria behave.
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 shinyapps.io 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 shinyapps.io you get access to cloud resources that have ShinyServer installed. However, shinyapps.io 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 24⁄7, 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 shinyapps.io this can decrease recurring costs a lot.
- Setting up a server, and installing all dependencies will take more time than signing up for shinyapps.io
- 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 shinyapps.io 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.
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 shinyapps.io to an instance running Docker:
- There is no shortage of active hours anymore. The app runs 24⁄7, 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.
- Visualizing Bikesharing Trips from StadtRad with kepler.gl
- Learn How to Dockerize a ShinyApp in 7 Steps
- A Brief Introduction to Wikidata
- 4 Steps to set up a free online Scraper with RServer and AWS
- Learn how to select the best performing linear regression for univariate models
- Clustering spatial data without ML to find homogeneous areas
- How you can use linear regression models to predict quadratic, root, and polynomial functions
- Facts + Figures of the Bike-Sharing System StadtRad (Hamburg)
- Using Big Data to Identify Bike-Sharing Customers