How to deploy a Shiny app for production

[This article was first published on pacha.dev/blog, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

If this post is useful to you I kindly ask a minimal donation on Buy Me a Coffee. It shall be used to continue my Open Source efforts.

You can send me questions for the blog using this form and subscribe to receive an email when there is a new post.

I got this question for the blog:

Hello pacha.dev, it’s a pleasure to meet you. My name is Santiago from Peru. I’ve been following your work since tabulapdf gran paquete, and now with tabler and d3po, great things are coming. I was checking out the OPEN TRADE STATISTICS dashboard, and I noticed that it’s a shiny app. I’d like to know if you have any recommendations on how to host a shiny app for production (shiny.apps.io falls short for production), if you have a preference for AWS or Azure, and if there’s a blog post about that, that would be great. Greetings from Peru.

Thanks, Santiago! Your question is properly worded and specific. I will try to honour the effort by providing a useful answer.

Shinyapps.io is a great service to host Shiny apps, but as you mentioned, it has limitations for production use. Being fair, the limitations apply to the free tier only. Paid plans offer more resources and capabilities, and it is a great option for paid hosting. I have used it and ot does its job well.

However, Shinyapps.io can be expensive, and there are cheapter alternatives if you are willing to manage your own server. For a long time I used DigitalOcean, to the point I created a variety of R/Shiny images for their marketplace. At some point my account was suspended without explanation, so I tried other providers and I cannot recommend it now.

Currently, I use Kamatera to host my Shiny apps. They offer a variety of server configurations at a reasonable price, and their support is good regarding SSH and other remote access methods. With Kamatere you will need to set up the server yourself, including installing R, Shiny Server, and any other dependencies your app requires. This gives you more control over the environment and can be more cost-effective for production use. Please note that I do not hjave a promotional code nor I receive fees for recommending Kamatera; I just like their service.

I have also used AWS, which is a robust and scalable option for hosting Shiny apps. AWS offers services like EC2 for virtual servers and they offer a very fast hosting service. However, AWS can be complex to set up and manage, especially for those unfamiliar with cloud services. It can also be more expensive than other options.

Kamatera is more simple. You get access to a plain virtual machine, they offer multiple Linux distributions and Windows, but you need Linux for Shiny Server. After setting up the server (e.g., how much RAM and the number of cores), you can install R, Shiny Server, and any other necessary packages. You will also need to configure security settings, such as firewalls and HTTPS certificates.

These days we have a wide range of tutorials on YouTube, which will show you the required steps:

  1. Set an SSH key to access the server securely.
  2. Install R and Shiny Server on the server (same as doing it on your local Linux machine).
  3. Install NGINX or Apache for the web server (I use NGINX).
  4. Configure the firewall to allow traffic on the necessary ports (443 for HTTPS, 3838 for Shiny, 22 for SSH etc.)
  5. Install all the required R packages for your Shiny app.

To simplify step 5 I really recommend golem to design your app as an R package, which will largely simplify the deployment and dependencies management. I have two videos explaining golem basics: part 1 and part 2.

These general steps exclude configuring a SQL database, internal API or configurations to connect to a 3rd party API, which are steps beside setting a domain name and HTTPS certificates, which are also important for production use. Multiple blogs explain how to use Let’s Encrypt to obtain free SSL certificates and configure them with NGINX or Apache to serve your app securely from a website such as https://santiago-shinyapp.com.

I hope this helps you to get started with hosting your Shiny app for production use!

Now the shameless self-promotion part: You can hire me to do configure a server for your project. You can contact me on Fiverr.

To leave a comment for the author, please follow the link and comment on their blog: pacha.dev/blog.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)