In this video, Appsilon’s VP of the Board & Co-Founder Damian Rodziewicz explains best practices for scaling Shiny applications in production. Damian explains three of the areas that Appsilon focuses on to scale Shiny applications: Frontend Leveraging, Extracting Computations, and creating a stable and scalable Architecture.
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.
If you intend to scale your Shiny app, there are two concepts we need to explore: Vertical Scaling and Horizontal Scaling.
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.
Below is a quick rundown of each area, but please reference the video presentation for a full explanation. Above all, it’s important to Make the Shiny Layer Thin. 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.
shinyjsallows you to do this. It’s best used to make some quick toggles.
Plumberlibrary 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.
Appsilon is an RStudio Full Service Certified Partner. We are global leaders in Shiny and we specialize in advanced enterprise Shiny apps for Fortune 500 companies. Reach out to us at [email protected].