Chapter 23. Performance
A Shiny app can support thousands or tens of thousands of users, if developed the right way. But most Shiny apps are quickly thrown together to solve a pressing analytic need and typically begin life with poor performance. This is a feature of Shiny: its allows you to quickly prototype a proof of concept that works for you, before figuring out how to make it fast so many people can use it simultaneously. Fortunately, it’s generally straightforward to get 10–100x performance with a few simple tweaks. This chapter will show you how.
We’ll begin with a metaphor: thinking about a Shiny app like a restaurant. Next, you’ll learn how to benchmark your app, using the shinyloadtest package to simulate many people using your app at the same time. This is the place to start, because it lets you figure out you have a problem and helps measure the impact of any changes that you make.
Then you’ll learn how to profile your app using the profvis package to identify slow parts of your R code. Profiling lets you see exactly where your code is spending its time, so you can focus your efforts where they’re most impactful.
Finally, you’ll learn a handful of useful techniques to optimize your code, improving the performance where needed. You’ll learn how to cache reactives, how to move data prep code out of your app, and how to use a little applied psychology to help your app feel as fast as possible.
I recommend watching Joe Cheng’s rstudio::conf(2019) keynote “Shiny in Production: ...
Get Mastering Shiny now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.