This document discusses dashboard development in R. It describes why R is useful for dashboards due to its ease of data acquisition and extensive libraries. It then demonstrates acquiring Apple Health step count data from an XML file, cleaning and transforming the data, and consuming it in an R module. Finally, it outlines several tools for creating dashboards in R, including Shiny, flexdashboard, and Plotly, and provides examples of dashboards using streaming data, bus schedules, and Apple Health data. It encourages further learning through online courses and recommends following the author online for more information.
2. @rickwargo
• Works at InfoMC, Inc.
Director, Architecture and Development
• You’ll see me
• At the beach
• Behind the camera
• Cooking
• Developing
• Exploring
• Frolicking with my family
• Published R package – lrequire (makes dashboard development easier)
• One of the original ten Alexa Champions
• Presentation available at
https://www.rickwargo.com/dashboard-development-in-r/
6. Let’s Use Apple Health Data - Steps
Data Acquisition from Analytics Playbook
Export Health Data from iPhone
1
3
2
7. Get Data Presentation Ready
• Acquire data
• Clean and Tidy
• Tidy: Get the data in a format that is easy to
manipulate, model, and visualize
• observations are in rows
• variables are in columns
• contained in a single dataset
• Augment
8. apple_health_data.R
library(lubridate)
library(XML)
# load apple health export.xml file
xml <- xmlParse("~/Code/R/AppleHealthData/apple_health_export/export.xml")
# transform xml file to data frame - select the Record rows from the xml file
steps.df <- XML:::xmlAttrsToDataFrame(xml['//Record[@type="HKQuantityTypeIdentifierStepCount"]'], stringsAsFactors = FALSE)
# make value variable numeric
steps.df$value <- as.numeric(steps.df$value)
# make endDate in a date time variable POSIXct using lubridate with eastern time zone
steps.df$endDate <- ymd_hms(steps.df$endDate, tz="America/New_York")
# augment data - add in year month date dayofweek hour period columns
steps.df$month <- format(steps.df$endDate,"%m")
steps.df$year <- format(steps.df$endDate,"%Y")
steps.df$date <- format(steps.df$endDate,"%Y-%m-%d")
steps.df$dayofweek <- wday(steps.df$endDate, label=TRUE, abbr=FALSE)
steps.df$hour <- format(steps.df$endDate,"%H")
steps.df$period <- format(steps.df$endDate, "%Y-%m")
steps.df <- steps.df[steps.df$period>"2016-09",]
module.exports <- list(steps=steps.df, summary=summary.df)
12. Dashboard Tools in R
Shiny
• Host on your own servers or on Rstudio’s hosting service
• No web development skills required, but you can if you desire
• shinydashboard -- install.packages("shinydashboard")
• shinythemes -- install.packages("shinythemes")
• Extensible
flexdashboard for R
• Uses R Markdown for publication (knitr is another great option)
plotly Dashboards ($$)
• Beautiful, publication-quality graphics
• API’s for multiple languages including R, Python, Matlab, …
13. Create a Shiny Dashboard
• From R Studio, create a Shiny Web App
• Run app locally (to test)
• Publish to share with small team – other hosting options available
20. More Learning
Coursera – Data Science Specialization
R Libraries
• lrequire: Sources an R "Module" with Caching &
Encapsulation, Returning Exported Vars
Often the first choice for statistics, data analysis, and machine learning, R has a variety of use cases that make it a great fit. And due to the open-source nature of R, there are many packages that make R a great tool for developing dashboards. In this session, we will discover and understand how to build dashboards in R using a few different patterns. We will also understand how to deliver this content to the consumer in multiple forms, including on-demand (web and bot), interactive (web), and batch (email). You will leave this session with an understanding of how to start developing dashboards in R and how to deliver them to your user community. To get the most from this session, some general knowledge of R and programming languages is required.
Why Dashboards? You wouldn’t be here if you could not answer this part of the question.
We will not cover how to build a good dashboard – this is an entire presentation in itself.
We also will not cover selecting the right KPI’s or dashboard representations
For an introduction to R and SQL Server, see Dan Hartshorn’s session immediately following in this room!
Compare creating dashboards in Excel – semi easy to acquire and augment data. Cleansing is a bit more difficult. Delivery is challenged. Not a lot of reusable components. Excel is hard – a study in 2013 found 88% of spreadsheets had significant errors.
And best of all, it’s cheap, if not free! Of course, if you want to pay for support and tools, R can do that, too!
It’s all about the data and the data insights
All dashboards are data-driven with regularly updated (and correct) data
Ideally, in a real dashboard environment, this data refresh would be automated.
We won’t cover all of the different ways of acquiring data. In this session, we’ll get data from an XML source (first time for me:)
80% of the effort of analysis is spent just getting the data ready to analyze, the process of data cleaning
Getting data tidy: getting the data in a format that is easy to manipulate, model, and visualize
R is an awesome tool to get this job done, and get it done consistently
Not the perfect example of making a dataset tidy, however…
Augments the data set with time data
Makes it available for quick reuse
I typically will spend a good amount of time acquiring and cleansing data and make available for reuse to a dashboarding routine
To consume the data, use the nifty lrequire module to load the data (one time) and return. Future uses will pull from memory and be quick – the acquisition/cleansing process is typically time consuming
This becomes integral for an iterative cycle around dashboard development
Run through this in R
All different types of dashboards can be made with R – with rich visualizations, static and dynamic content, and a variety of libraries to make it easier
Shiny, by R Studio, the same folks who brought the defacto R IDE
These are some of the major players when it comes to dashboard tools. There are many more and most of these are free!
Do the Create a New Shiny Web App, show it and publish it to show hosted solution. Not what I would call a dashboard, “yet” but can be turned into one.
Do the Create a New Shiny Web App, show it and publish it to show hosted solution. Not what I would call a dashboard, “yet” but can be turned into one.
Do the Create a New Shiny Web App, show it and publish it to show hosted solution. Not what I would call a dashboard, “yet” but can be turned into one.
Written with R Markdown so that it is easy to format.
Output to HTML or PDF
Send in an email
Demo flex.Rmd
Demo email.R
Written with R Markdown so that it is easy to format.
Output to HTML or PDF
Send in an email
Demo flex.Rmd
Demo email.R
Beautiful graphics
Support in different languages (R, Python, build one online)
$$$
Very cool self-service dashboarding/reporting!
Coursera course started May 29, 2017 – lots of opportunities to sign up