Building Big Shiny Apps

A Workflow

What's a Shiny App?

Shiny is a framework for building web applications that can communicate with R. No knowledge of HTML, CSS or JavaScript is required.

On the plus side:

  • Easy to use
  • Fast for prototype

On the down side:

  • Can get tricky for big apps

What's a BIG Shiny Apps?

Shiny is perfect if you need to create Data Science prototypes rapidly.

It can also be used in production, but it then becomes more complex.

  • Millions of lines of code
  • Several coders
  • Potentially numerous users
  • Scaling matters
  • Users who are not “coders”

Building Big Shiny Apps

The Challenges

What are the challenges?

Finding a Good User interface

(and stick with it)

Simplicity is the key.

'Simplicity is the most difficult thing to secure in this world.'

Working simultaneously on the same app

Adopt an app structure and choose tools that will allow multiple peoples to work safely (and efficiently) on the same application.

Making it Production Ready

Create an app that is robustly tested, maintainable, and deployable into production.

Building a Good User Interface

A big Shiny app might be used by people who are not “tech literate”, and need a simple, easy to use and easy to understand application.

How to do that?

  • Simplicity is the key
  • Do what’s necessary, no more, no less

Developping as a Team

Building a big shiny app means that several coders will work on that app. Choose tools and structure that will fit collaborative work.

  • Use version control.
  • Split your app into pieces so that everybody can work on his own piece (Shiny modules).

Scale Big Shiny Apps

Most of the time, building a big Shiny App means that it will be scaled to numerous users, that it will be used for a (relatively) long time, and that you might implement new things on it in the future.

  • JavaScript can make the app lighter (don’t make R do things it doesn’t need to do).
  • {future} and {promises} are your friends.
  • Using modules allow to implement new things more easily in the future.

Maintain

Once your app is in production, you need to make it maintainable.

Making a software maintainable is:

  • Using modules make the application easier to maintain: “bite size” pieces of code are easier to understand on monolithic, 1000s of lines long files (even more if you need to pass this application to someone else in the future.
  • Create regression tests so that the application doesn’t suddenly break.
  • Ensure R & package stability over time (notably: the version numbers).

Building Big Shiny Apps

Step by step

Design

Don't rush into coding the app.

Start simple: maybe just with a pen and a piece of paper. Draw the app here, and define the content.

Rmd are your friends.

  • Will help you think about the content

Prototye

Go “UI first” - define the outline of the app, whithout focusing on the backend.

  • Will freeze the app content and fonctionalities.
  • Can help you see potential pitfalls before it’s too late.
  • Once this UI prototype is agreed upon, everybody know where the app is going.

The {shinypsum} package has been especially created for that: https://github.com/ThinkR-open/shinipsum. See also {fakir}: https://github.com/ThinkR-open/fakir.

Build

Now that the UI is designed, time for building the hardcore backend.

  • Create the R code that processes the app inputs.
  • Now, there should be no “surprise implementations” as everything has been fixed by the prototyping phase.
  • As a team, it’s easier to see where everyone is going.

Secure

Use continuous integration and tests.

  • Allow to check the app on every push to the version control system.
  • Don’t implement things that breaks the app.
  • It’s hard to test Big Apps: there are a lot of scenarios and they might be long to perform. Don’t loose time doing it by hand.

Deploy

You can't just put the app on a server and run it as is.

  • Docker
  • Shiny Proxy
  • RStudio Server
  • RStudio Connect

Building Big Shiny Apps

Tools

Tools

What do I need?

img

Package

Building your app as a package allows you to make your application self-contained, with documentation, dependencies, tests, and to be served in any R session.

img

Git

Git is a version control system that allows people to collaborate on code by tracking changes, and allows to work together on the same project but in different branches.

img

Shiny Modules

Using Shiny Modules allows to work on small, self contained features. Everybody can then work on their own module. It also allows to implement or remove feature easily.

img

shinipsum

The {shinipsum} package allows to create random shiny UI elements so that it's easy to prototype an application interface. See also {fakir} for fake datasets.

img

golem

{golem} is the future version of {shinytemplate}, a package providing a template for robust shiny apps, with a series of tools for integrating new elements to the application.

(We're still working on it).

img

CI & testing

Several tools exist to do continous integration: gitlab CI, travis, appveyor...

The {testthat} package is also used to test the code of the "business logic" functions from the Shiny App.

img

Testing

Find a reliable testing environment for stable / scalable application

{shinytest} / {katalon} / {shinyload}

img

Docker / Shinyproxy / Shiny server / connect

These tools allows you to scale your Shiny Application, so that it can be used by hundreds of people.