Previous chapter
DashboardsIntroduction
Next chapter

What is a dashboard?

Dashboards are typically created to monitor specific key metrics on a continous basis. These metrics can also be displayed using interactive tables and visualizations. Most dashboard solutions focus on a single page layout - so no matter which device you are using the dashboard should display all key metrics on a single screen. This requires responsive web designs so that desktop computer- as well as mobile devices’ screens are supported. Most importantly, users can easily retrieve current information like sensor data, business numbers, etc. on demand which enables them to answer pressing questions quickly.

Additional features of a dashboard:

  • Automatically updating
  • Not just based on user gestures
  • But also when data source changes
  • Many viewers looking at the same data
  • May or may not be interactive

Drill-Down

Typically, it may also be required to find out specific reasons once a key metric looks odd, is above/below limits, etc - thus a dashboard might also need to include a drill-down functionality for users to find out the reasons once a warning occurs.

Data Updates

Instead of sending multiple Excel/PDF reports each day/week/month dashboards have the nice property to always show the most current information or give users the the possiblity to retrieve past reports on demand. The typical pipeline may look as follows:

  1. You have new data coming in — constantly, continuously, or on a schedule
  2. When new data comes in, it’s automatically received, and transformed, aggregated, summarized, etc.
  3. May want to call attention to exceptional results

For constantly changing data it might be necessary to update the dashboard regularly.

Exercise

dataset <- reactive({
  result <- read.csv("data.csv")
  invalidateLater(5000)
  result
})
output$plot <- renderPlot({
  plot(dataset())
})

Reactive Readers

Reactive File Reader

  • Reads the given file (“data.csv”) using the given function (read.csv)
  • Periodically reads the last-modified time of the file
  • If the timestamp changes, then (and only then) re-reads the file
dataset <- reactiveFileReader(
  intervalMillis = 1000,
  session = session,
  filePath = "data.csv",
  readFunc = read.csv
)
output$plot <- renderPlot({
  plot(dataset())
})

Reactive Poll

  • reactiveFileReader is limited to files on disk. It doesn’t work for non-file-based data sources like databases or web APIs
  • reactivePoll is a generalization of reactiveFileReader
  • checkFunc: A function that can execute quickly, and merely determine if anything has changed
    • Should be fast, as it will block the R process while it runs! The slower it is, the greater you should make the polling interval.
    • Should not return TRUE or FALSE for changed/unchanged. Instead, just return a value (like the timestamp, or the count); it’s reactivePoll’s job, not yours, to keep track of whether that value is the same as the previous value or not.
  • valueFunc: A function with the (potentially expensive) logic for actually reading the data

flexdashboard vs. shinydashboard

There exist two common approaches to implement Shiny dashboards in R: flexdashboard and shinydashboard.

flexdashboard

Flex dashboards (name from Flexbox + Dashboard) implemented by the package flexdashboard are the easiest route to create your first dashboards. Based on RMarkdown (*.Rmd) files flex dashboards can be created and displayed within RStudio. Compared Shiny and shinydashboard they are using the browser flexbox engine, which alters its items’ width and/or height to best fill the available space on any display device. A flexbox layout expands items to fill available free space, or shrinks them to prevent overflow. It is therefore very easy in flexdashboard to support layouts filling the entire vertical space on the screen. Besides all great features and usability coming with flexdashboard they do not offer the high degree of flexibility as shiny or shinydashboard apps. If used with the shiny runtime, they tend to have higher load times.

shinydashboard

Shinydashboards are based on the AdminLTE (https://adminlte.io) Bootstrap framework to create nice-looking, interactive dashboards. Under the hood, shinydashboards look much more like ordinary shiny apps - they are just using a slightly different vocabulary. Compared to flex dashboards they offer a higher degree of flexibility and customization at the price of a steeper learning curve.

Static vs. Dynamic

A general question for users is whether they need their dashboard static or dynamic. Currently, only Flexdashboards offer the option to be compiled as static dashboards. Static dashboards are simply .html files with all data and user interfaces baked in. The advantage of static dashboards is their load times and the fact that they can simply be shared with other collegues (e.g. via email). By adding the option runtime: shiny to the YAML header Flexdashboards can simply be turned into Shiny applications. By contrast, Shinydashboards do not offer the option to be compiled as static .html files.

To sum it up:

  • Static
    • Code runs once and generates HTML page
    • All required data is essentially packaged inside HTML page
    • No visualization based on dynamic DB queries possible
  • Dynamic
    • Client web browser connects to an R session running on server
    • User input causes server to do things and send information back to client
    • Interactivity can be on client and server
    • Can update data in real time
    • User potentially can do anything that R can do

flexdashboard vs. shinydashboard

Below the Pros and Cons of flexdashboard and shinydashboard:

flexdashboardshinydashboard
RMarkdownShiny UI Code
Super easyNot quite as easy
Static or dynamicDynamic
CSS flexbox layoutBootstrap grid layout