In my previous post I had written about how to host an R shiny app on AWS cloud. Once the app is hosted successfully, your end users can access the app easily. But what if your end users want to host the app locally in their system and possibly make changes to the app itself?
While I had demonstrated a ‘’Hello world” version in my previous article, in real work environments the R shiny app can get really complex. Some R shiny apps can have complex algorithms running in the back end for e.g churn prediction, probability of failure of equipment, weather prediction etc. All these algorithms written in R invoke lot of packages. Some of these packages may not be compatible with R version installed in the recipients’ system.
I too faced many hurdles while hosting an R shiny app in real environment, ranging from missing data files, R work spaces, missing R shiny app components (UI.R & Server.R) and of course not to mention the various missing or not ‘up to date’ library packages. I wished if there was a way where the people responsible for developing the R shiny app had just given me a zip file with all dependencies taken care off and all I had to do was unzip it and run the code to host the app. Wishful thinking some would say, but not really. Enter the ‘Docker’.
What is a Docker?
Though the software engineering folks might be already aware of Docker, I will try to explain in layman terms for people unfamiliar with it. So here it goes
Imagine you are in some remote town on Earth. You wish to build a toy building out of Legos, but your town neither has Legos nor do you know how exactly to put the pieces together to make a building.
Enter your friend ‘ Docker’ . The docker has already pre built the building with Lego pieces and packaged it in a gift box. Talk about an Ideal Christmas Gift 😉. Now all you have to do is unpack it and keep it on your table. Tada !!! your wish has come true.
Now what are the hassles you just avoided
· Buying the right Lego pieces which help you build the toy building
· Putting the Lego pieces together
· Wasting time
Now let’s extend the Lego analogy to delve deeper into Docker.
· The Lego pieces are akin to your code and its dependencies (packages, libraries), and the environment (OS, Version of Software, IDE).
· The gift box is the ‘container’ safely containing all the components.
· You unpacking and safely putting it on table is deployment of the code.
While doing the above, the advantages you had were
· You did not have to install the latest version of the language or its packages/libraries
· You did not have to configure your environment
· You could directly deploy the code and yes you saved lot of time
Alrighty then, now that we have an intuitive idea of what Docker is, lets push the envelope and explore it more technically.
Docker Under the Hood:
The Docker is basically a Container. Container is a running instance of an image.
Image is a snapshot of the environment in which you ran the code. It contains the operating system, software and library packages.
A dockerfile helps define an image. It is a series of steps to create an image. It will contain details of which library packages to load, where to copy the files from and to which location.
The below picture illustrates the process aptly
An excellent tutorial on Dockers by Jake Wright can be viewed in the below link.
So folks, the Docker helps in hosting an R shiny app as depicted below. System B hosts R shiny app successfully thanks to the Docker.
Stay tuned for Part 2 where I illustrate how to dockerize the R shiny app step by step.
Hope you liked my article.
You can reach out to me on