Developing a Shiny app is relatively straightforward, but deploying it to a production environment is a whole another set of challenges.
If you’re unfamiliar, R Shiny is a powerful web application framework for building interactive data visualizations, dashboards, and other data-driven applications. At Appsilon, we’re a big fan of it, and have used it to develop applications for Fortune 500, even Fortune 10 companies!
We know every challenge that comes with the deployment. In this article, we will explore the most common options for deploying a Shiny app and their pros and cons. By the end, you will understand the different deployment options and how to choose the best one for your needs.
We’ll compare all 5 options through 5 comparison points:
Let’s dig in!
Looking to get your software FDA/EMA approved? Make sure you’re following these 7 Good Software Engineering Practices (GSEP).
Table of contents:
Shiny has a functioning web server and can be run simply with a container or directly on a virtual machine.
Utilizing Docker (or other container technologies) is the most common path to containerize the application, and host it in any platform that allows the hosting of containers. You can even depend on the scaling ability of the platform to scale the number of instances running to serve clients.
This is the least friendly solution, as everything needed to run the application has to be covered – from the code being deployed, to resolving authentication, controlling access, and coordinating scaling.
Back to our 5 comparison points:
You have 3 hosting options for pure Shiny deployments:
With this hosting option, you’re essentially utilizing a single virtual machine (or a group of virtual machines with horizontal scaling abilities) to host your applications.
It involves setting up all the necessary routing to the machine, configuring an image to host the applications, and maintaining the environment.
For this scenario, the overhead of managing and configuring the environment is quite big, scaling can be a challenge, and it’s the least preferred option, but still an option for simple use cases, or early adoption scenarios.
With this option, you’re utilizing one of the most recommended strategies for application deployment. Containerizing a Shiny application is relatively simple, and you can then host it on a container hosting platform; be it a self-managed docker swarm cluster, a single virtual machine with docker, or even a Kubernetes cluster.
While this option eases up on a few concerns as the previous option, it’s still a heavily unmanaged solution, and despite scaling being simpler, there are still a couple of challenges.
It’s a preferred option for simple use cases, granted there is a team that can support the infrastructure.
Other options fall into a more managed scenario, e.g. utilizing AWS ECS with Fargate, utilizing Azure App Services, or other types of solutions that would give you a managed platform to host containers, with as little overhead as possible. Keep in mind that you’ll need to have some basic knowledge on how to configure these things in the cloud.
This option builds on the previous one and comes down to having less overhead in terms of managing the deployments and maintaining the platform.
It’s still good for simple use cases. Advanced scenarios could run into some overhead of customizing the solution.
Pursuing this solution is a viable option. We have successfully developed custom applications for custom deployments multiple times in cases with limited workloads and a limited number of users.
This is a long-term solution, and we can justify this investment in the long term, especially if there is a team that can maintain and develop the environment for the applications, and adjust the applications to fit into the environment.
Go with this route if the use cases for your application are simple with non-demanding scaling, a few users, and a reduced number of applications.
Shinyapps.io is a platform that hosts shiny applications. It has several platform tiers, including a free one.
It’s a cost-effective solution offered by Posit, but has a couple of security concerns, and limited scaling potential. It’s optimal for testing simple, not sensitive, and small-scale use cases.
This solution might be a good fit if you can answer the following 4 questions positively, from Posit themselves:
The limitations are quite serious, but Shinyapps.io still has its place. Let’s compare it through are set of 5 points next:
Authentication starts only at the Standard Tier.
With ShinyApps.io, we can’t compare different hosting options like we did for Vanilla Shiny, for obvious reasons.
Shinyapps.io is a good solution for your application deployments when you need an out of the box solution, but may not be the best choice if your app will be used heavily, will be critical to users and has high compliance requirements.
Appsilon can help set up and consult on the best scenario for this implementation, and help you decide if this is the right solution for you. Feel free to reach out.
Shiny Server Open Source is maintained by Posit, and it’s a solution that can be hosted in a dedicated VM or can be containerized but has to be self-hosted. It can run multiple apps, but only a single process per application.
Here are our thoughts on the 5 comparison points:
Hosting Shiny Server Open Source is similar to Vanilla Shiny. The major difference is that you get less overhead from configuring and managing an environment since you’re utilizing a framework that allows hosting multiple Shiny apps.
These are your options:
Opposed to Vanilla Shiny hosting, this is a preferable way to host applications. You can utilize resources more efficiently if you deploy multiple applications, and Shiny Server helps with the routing and application configuration.
There’s still some overhead with managing virtual machines, but it’s easier for simple use cases.
Dynamically scaling could be a challenge here, but scaling up a single instance is relatively easy.
This deployment option doesn’t support the use of containers, but the solution itself could be containerized.
It’s not a recommended pattern, as this deployment technology is more meant to be run directly on virtual machines, with fewer resources and environment constraints.
Shiny Server Open Source is a viable solution that mostly fits simple application scenarios. If apps are complex and need extensive resources, it would affect the performance for the rest of the users as there is only one instance per application.
It fits best for non-complex applications, with non-intensive workloads, and a low number of users, without having complicated authentication schemes.
For this scenario, Shiny Server Open Source is one of the best solutions, and Appsilon has worked extensively with applications that fall into these requirements.
Shiny Proxy is an open-source solution maintained and developed by OpenAnalytics.
It’s a simple service that allows scalability for applications, leverages container technology and provides authentication out of the box. It can be resource-heavy, though. It can host other applications that are not R-centric.
Here’s our breakdown of the 5 key points:
Shiny-Proxy is a scalable solution from the get-go, and you have a couple of options to deploy applications:
The solution uses Docker as its backend for spawning containers (with apps). Therefore Docker has to be installed on the virtual machine. Shiny-Proxy itself can be run in a container or as a regular Java program.
As this option creates one container per user, it can quickly deplete the resources available for a virtual machine, so for a high number of users, it is not recommended to host it directly in a single VM.
There’s some potential to utilize multiple virtual machines, but this is counterproductive when Shiny-Proxy can take advantage of container technologies directly.
This is the scenario for which Shiny-Proxy is more adequate. You can utilize a Docker Swarm or Kubernetes platform to host the spawned containers, and Shiny-Proxy itself could also be containerized.
For small to medium user bases, with multiple applications, this scenario is a good fit. However, further consideration has to be given to the extra resources necessary to run a container per user.
Shiny Proxy allows for more complex setups and guarantees some level of scalability for the applications hosted with it. The limitation of one user per container is by design, and it’s great for small to medium utilization. It allows for complex setups with authentication and can work with other types of applications.
If the number of applications that need to be deployed is high or the application has a medium to big user base, it can easily consume a lot of resources. It still has some overhead in setting up, managing, and monitoring.
We conducted a benchmark test comparing ShinyProxy and Posit Connect. Check out the outcome in this blog post.
Posit Connect is the new iteration of hosting solutions from Posit, following Shiny Server Pro, the enterprise version of Shiny Server Open Source, offered by Posit.
This is the most battle-tested and efficient solution in terms of resource usage. It works well with complex scenarios.
This is our overview of the 5 comparison points:
First time using Posit Connect? Explore our beginner’s guide to help you get started.
Posit Connect is a solution optimized for all kinds of deployment complexities. We’ll explore:
Posit Connect can be hosted directly on virtual machines, be it in a cluster configuration or single server configuration. Having cluster configuration means that each Connect can communicate with each other, and coordinate resources between each other. It is possible to set up auto-scaling in this scenario with scaling sets of virtual machines.
This is the traditional path to install Posit Connect and it’s a stable setup. With little more overhead in comparison to managing virtual machines.
Posit Connect has one capability called “off-host execution” in which currently it is supported to have processes for applications being launched on a Kubernetes Cluster, in containers.
This allows for a much more scalable solution in the long run, but it also provides some overhead in managing a Kubernetes Cluster. It’s ideal for complex deployments, and heavy usage, and recommended if there is already a Kubernetes Cluster deployed and being used in other contexts.
Posit Connect is the enterprise battleship for hosting Shiny (and now also Python) applications. It is the easiest solution to maintain long term, but that comes as a premium with its licensing costs. It serves well small use cases, and excels with complex and demanding workloads.
It is developed to be easily maintained and used, and integrates seamlessly with other Posit Products.
As a Posit Partner, Appsilon has extensive experience hosting, managing and optimizing this solution for small to big use cases.
To conclude, there are numerous ways to deploy an R Shiny application.
Some options leverage open source technologies, others come with licensing costs. Some are tailored to simple scenarios where you have to do everything from scratch, others offer everything but a kitchen sink. In other words, you have options.
For simple scenarios, we recommend going with Shiny Server Open Source or a self-hosted Vanilla Shiny application. For more complex scenarios, Shiny Proxy and Posit Connect would be more appropriate, being that Posit Connect is the most effective solution for every scenario, but has bigger upfront costs due to its licensing.
In terms of deployment options, it heavily depends on the capabilities to maintain the solution long-term, and the scaling requirements, being that Posit Connect is more managed and has better resource efficiency.
We also recommend going with containers everywhere it could be possible, for almost all the scenarios, as it’s the most effective solution in the long run.
Appsilon has experience with all of these scenarios and technologies, so don’t hesitate to reach out. We’re a video call away to help you decide which option fits best your use case.
Speaking of containers, you should really try Docker for R. Follow our guide to containerize your first R script.
This article was co-authored by Dario Radečić.
The post appeared first on appsilon.com/blog/.