Video: How to Scale Shiny Dashboards

By:
Damian Rodziewicz
October 18, 2020

[embed]https://youtu.be/oW2U2Ti8P-U[/embed] <p style="text-align: center;"><span class="style-scope yt-formatted-string" dir="auto"><em>This presentation was a part of a joint virtual webinar with <a href="https://appsilon.com/shiny" target="_blank" rel="noopener noreferrer">Appsilon</a> and RStudio entitled "Enabling Remote Data Science Teams". Find a direct link to the presentation <a href="https://www.youtube.com/watch?v=oW2U2Ti8P-U&amp;feature=youtu.be" target="_blank" rel="noopener noreferrer">here</a>. </em></span></p> <h2>How to Scale a Shiny App to Hundreds of Users</h2> <span data-preserver-spaces="true">In this video, Appsilon's VP of the Board &amp; Co-Founder Damian Rodziewicz explains best practices for scaling <a href="https://appsilon.com/shiny" target="_blank" rel="noopener noreferrer">Shiny</a> applications in production. Damian explains three of the areas that Appsilon focuses on to scale Shiny applications: </span><a href="https://appsilon.com/r-shiny-faster-updateinput-css-javascript/" target="_blank" rel="noopener noreferrer"><strong><span data-preserver-spaces="true">Frontend Leveraging</span></strong></a><span data-preserver-spaces="true">, </span><a href="https://appsilon.com/shiny-worker-package/" target="_blank" rel="noopener noreferrer"><strong><span data-preserver-spaces="true">Extracting Computations</span></strong></a><span data-preserver-spaces="true">, and creating a stable and scalable </span><a href="https://appsilon.com/alternatives-to-scaling-shiny/" target="_blank" rel="noopener noreferrer"><strong><span data-preserver-spaces="true">Architecture</span></strong></a><span data-preserver-spaces="true">.</span> <span data-preserver-spaces="true">R Shiny applications are fast by default but can become extremely slow if they are not properly built, especially when there are tens or hundreds of people using them. Having best practices in mind from the beginning of the project can save you a lot of trouble down the line. </span> <blockquote>Learn More: <a href="https://appsilon.com/why-you-should-use-r-shiny-for-enterprise-application-development/" target="_blank" rel="noopener noreferrer">Why You Should Use R Shiny For Enterprise Application Development</a></blockquote> <h4>Vertical and Horizontal Scaling</h4> If you intend to scale your Shiny app, there are two concepts we need to explore: <strong>Vertical Scaling</strong> and <strong>Horizontal Scaling</strong>. <span data-preserver-spaces="true"><img class="aligncenter size-large wp-image-5607" src="https://wordpress.appsilon.com/wp-content/uploads/2020/10/001-1-1024x661.png" alt="Horizontal and vertical scaling" width="1024" height="661" />It's best to start with proper vertical scaling - you should make sure the application is fast and robust in the first place while running on a single machine, and then you can add as many machines as you want in an efficient way (horizontal scaling). With this in mind, let's return to our three previously mentioned areas: Leveraging Frontend, Extracting Computations, and Setting the Architecture. </span> <img class="aligncenter size-large wp-image-5608" src="https://wordpress.appsilon.com/wp-content/uploads/2020/10/002-1-1024x485.png" alt="Pillars of making Shiny apps faster" width="1024" height="485" /> <span data-preserver-spaces="true">Below is a quick rundown of each area, but please reference the <a href="https://youtu.be/oW2U2Ti8P-U" target="_blank" rel="noopener noreferrer">video presentation</a> for a full explanation. Above all, it's important to <strong>Make the Shiny Layer Thin. </strong>This means that Shiny should only be doing the work that it's best at – creating an interface between R and your browser.  The rest of the work (such as interactivity or long computations) should be offloaded to the browser or handled by the database, etc.</span> <h4><strong><span data-preserver-spaces="true">Leverage Frontend </span></strong></h4><ul><li><span data-preserver-spaces="true">Render inputs in UI and update them in Server - failing to do so requires re-rendering entire widgets, which makes the application run slower.</span></li><li><span data-preserver-spaces="true">Run inline JavaScript - the package <code class="language-r">shinyjs</code> allows you to do this. It's best used to make some quick toggles.</span></li><li><span data-preserver-spaces="true">Set all actions in JavaScript - handle things like button clicks with JavaScript, not with Shiny.</span></li><li><span data-preserver-spaces="true"> Learn more about leveraging frontend in Shiny <a href="https://appsilon.com/r-shiny-faster-updateinput-css-javascript/" target="_blank" rel="noopener noreferrer">here</a>.</span></li></ul> <h4><strong><span data-preserver-spaces="true">Extract Computations </span></strong></h4><ul><li><span data-preserver-spaces="true">Remote API - the <code class="language-r">Plumber</code> library is excellent for doing this. You rarely need the entire dataset when using the application, so why not filter it down first and then load only what you need when you need it. This logic is easily wrapped into a simple API.</span></li><li><span data-preserver-spaces="true">Use a database - loading large files in memory isn't scalable for tens/hundreds/thousands of users. Using a database can dramatically improve the performance of Shiny apps. </span></li><li>Are heavy calculations freezing your Shiny app? Appsilon is developing the <a href="https://appsilon.com/shiny-worker-package/" target="_blank" rel="noopener noreferrer">shiny.worker</a> package to address this problem. shiny.worker is currently still under development, but it can be made available to clients and non-profit organizations on request.</li></ul> <h4><strong><span data-preserver-spaces="true">Architecture</span></strong></h4><ul><li><em><span data-preserver-spaces="true">RStudio Connect and Shiny Server Open Source</span></em><span data-preserver-spaces="true"> allows you to deploy applications quickly.</span></li><li><span data-preserver-spaces="true">We use </span><em><span data-preserver-spaces="true">Ansible</span></em><span data-preserver-spaces="true"> - to provision the whole infrastructure, install requirements, </span><em><span data-preserver-spaces="true">RStudio Connect</span></em><span data-preserver-spaces="true">, and deploy the application.</span></li><li>Learn more about the options for deploying Shiny apps <a href="https://appsilon.com/alternatives-to-scaling-shiny/" target="_blank" rel="noopener noreferrer">here</a>.</li></ul> <h1><span data-preserver-spaces="true">Learn more</span></h1> <ul><li><a class="editor-rtfLink" href="https://wordpress.appsilon.com/shiny-worker-package/" target="_blank" rel="noopener noreferrer"><span data-preserver-spaces="true">shiny.worker: Speed Up R Shiny Apps by Offloading Heavy Calculations</span></a></li><li><a href="https://demo.appsilon.ai/" target="_blank" rel="noopener noreferrer">10+ Shiny Dashboard Examples</a></li><li><a href="https://appsilon.com/howto-css-and-shiny/" target="_blank" rel="noopener noreferrer">How to Use CSS to Style Your Shiny Dashboards</a></li></ul> <strong><span data-preserver-spaces="true">Appsilon is an <a href="https://appsilon.com/appsilon-data-science-is-now-an-rstudio-full-service-certified-partner/" target="_blank" rel="noopener noreferrer">RStudio Full Service Certified Partner</a>.</span></strong><span data-preserver-spaces="true"> We are global leaders in Shiny and we specialize in advanced enterprise Shiny apps for Fortune 500 companies. Reach out to us at </span><a class="editor-rtfLink" target="_blank" rel="noopener noreferrer"><span data-preserver-spaces="true">hello@wordpress.appsilon.com</span></a><span data-preserver-spaces="true">.</span>

Have questions or insights?

Engage with experts, share ideas and take your data journey to the next level!

Is Your Software GxP Compliant?

Download a checklist designed for clinical managers in data departments to make sure that software meets requirements for FDA and EMA submissions.
Explore Possibilities

Share Your Data Goals with Us

From advanced analytics to platform development and pharma consulting, we craft solutions tailored to your needs.

Talk to our Experts
speed up shiny
shiny dashboards
video tutorials
community
r
rstudio
infrastructure
tutorials