How to Make Production Ready Shiny Applications

[This article was first published on r – Appsilon | End­ to­ End Data Science Solutions, 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.

Marcin Dubel presents at X-Session

What defines a production-ready Shiny application? And more importantly, how do we get there?

Shiny is hands down one of the best dev tools available for quick production of Proof of Concepts (PoC). But here in lies a trap. People tend to mislabel Shiny as a poor production tool because they fall for the PoC trap. They make something quickly and then fall short when attempting to finalize the product.

Build, style, and scale your Shiny application with Appsilon’s Shiny Masterclass

The video presentation below guides you through key steps that Appsilon Software Engineer, Marcin Dubel, takes whether assisting a client or building an award-winning app. Follow along and learn his definition of done and how to get there.

Shepherding Your Shiny App from Proof of Concept to Production

Marcin Dubel, Software Engineer, Grand Prize Winner 2021 Shiny Contest

Abstract

One advantage of Shiny applications is that a proof of concept can be created quickly and easily. It’s a great way for subject matter experts to present their ideas to stakeholders before moving on to production. But making the app production-ready might require help from experienced software developers. You can make more headway by focusing on two areas: user experience and future maintenance. This way, you’ll be sure that the app is scalable, performant, bug-free, extendable, and enjoyable. Close collaboration between engineers and experts paves the way to many successful projects in data science and is Appsilon’s tried-and-true path to production-ready solutions.

The very first step should always be building a convenient and (importantly) reproducible workflow, so start by setting up the development environment and organizing the folder structure [renv + docker]. Once completed, engineers should limit the codebase by cleaning the code ( i.e., removing redundant comments, extracting the constants and inline styles [ymls + styler]).

Now the real fun begins. Follow the steps below to make the most of it:

  1. Extract the business logic into separate functions, modules, and classes [packages/R6 + plumber]. Restrict reactivity to a minimum.
  2. Check the logic [data.validator + drake].
  3. Add tests [testthat + cypress/shinytest].
  4. Organize your /www and move actions to the browser [shiny + css/js].
  5. Finally, style the app [sass/bslib + shiny.fluent].

And, voila! A world-class Shiny app is ready to onboard users hungry for data-driven insights.

Try Marcin’s award-winning game Shark Attack! and see how his methods make apps rise to the top!

Lessons Learned for Production-Ready Shiny Apps:

  1. Code Sharing
    • Do not store data files in the repo
    • Do not store credentials
  2. Development Environments
    • Projects and relative paths
    • renv
    • Docker
  3. Code Structuring
    • Use a package
    • Extract modules
    • R6 classes
  4. External Resources
    • Do not use inline CSS/JS in R code!
    • Keep all dependencies in /www
    • Minified files
    • Extract block of texts to an external file
  5. Tests & Continuous Integrations
    • Start each project with CI and test structure
    • Use templates
    • Add tests incrementally
  6. Checking Business Logic
  7. App Performance
    • Data
      • Load only the data you need
      • Efficient data libraries {fst}, {data.table}, {arrow}
      • Build API with {plumber}
    • Code
      • Keep calculations outside
      • Actions in the browser
    • Deployment
      • Deploy early
      • Prepare architecture for a number of concurrent users
  8. App Styling and UX
    • User adoption is key!
    • UX designer and mockups!
    • Collect feedback early and often

Set your rules, create reproducible reports, and ensure quality data validation with the data.validator package

Need to Speed Up Production?

At Appsilon we have the skills to build world-class enterprise Shiny applications. Our team of software engineers, front-end developers, graphic designers, and business analysts can handle any development needs. From Proof of Concept to launch and maintenance, Appsilon can rapidly deliver R Shiny applications and solve your most challenging problems.

Software Quality / Focused Teamwork

Article How to Make Production Ready Shiny Applications comes from Appsilon | End­ to­ End Data Science Solutions.

To leave a comment for the author, please follow the link and comment on their blog: r – Appsilon | End­ to­ End Data Science Solutions.

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)