Automatically Update Dashboards in Displayr
Dashboards and data can be automatically updated in Displayr. A key benefit of using Displayr, instead of traditional data science programs, is that it can be set up to schedule calculations to occur automatically, which will then automatically update a dashboard.
There are three components to automatically schedule calculations:
- The automatic updating of data.
- Automatic publishing of online documents (i.e., dashboards).
- Finally, automatic data exporting.
Automatically update data
There are four basic options for automatically updating data in a Displayr document. They consist of importing data sets via the URL, SQL, R Code, or our API. Please note that updating data does not cause the published document to automatically update; the next section describes the updating of the published document (dashboard).
Option 1: URL
The simplest approach to automatically updating data is to put a data file on the web (e.g., shared from dropbox), and select Home > Data Set (Data) > URL. This opens up a form in which you enter the web address (URL) of your file, and indicate how regularly you wish it to be updated (e.g., every 24 hours). This approach is only applicable when you are uploading a Data Set.
The basic workflow is:
- Import the data from the URL, specifying the frequency of updates.
- Update the data file at the web address itself (e.g., by manually saving a revised data file, or, via some other automated method).
Option 2: SQL
Importing via SQL is done in the same way as with a URL (i.e., Home > Data Set (Data) > SQL). The SQL icon is above and to the right of the URL icon on the Where is your data? form above.
The benefit of importing via SQL is that you do not need to create a data file. Once you have set up the SQL query, the data will automatically refresh.
The key disadvantage of using SQL is that the data file format has limited metadata, which means that you end up having to do much more work when performing the initial setup (e.g., typing in variable labels) and there is a bigger chance of changes in data definitions not being noticed, leading to incorrect analyses.
Option 3: R Code
The most flexible approach to updating data is using R code. The workflow is:
- Write R code to import the data (e.g., using foreign::read.spss or read.csv).
- Use one of the following functions to tell Displayr when to re-run the code: message, UpdateEvery or UpdateAt. I describe these functions in more detail below.
- Press the Calculate button.
The key benefit of this approach is the flexibility to manipulate the data in whatever way you please using R code. But a key disadvantage is that R’s tools for reading Excel and SPSS data files can be a bit buggy and difficult to use, resulting in data and metadata problems.
As an example, the code below updates every day, and shows the last three months of Alphabet share price data from NASDAQ. You can open a copy of the document used to create this chart in Displayr.
library(flipTime) UpdateEvery(1, "days", options = "snapshot") library(quantmod) getSymbols("GOOGL") chartSeries(GOOGL, subset="last 3 months")
Option 4: Displayr’s API
Displayr’s API can automatically update and perform some modifications of documents (e.g., creating new tables).
Automatic publishing of online documents (i.e., dashboards)
Documents are automatically created by using one of the following functions in your R Code: message, UpdateEvery or UpdateAt. For example, the following code causes the R Output or Data Set code to be recomputed every week and the resulting document to be republished.
library(flipTime) UpdateEvery(1, "weeks", options = "snapshot")
Whereas this code updates on the 15th of May 2017 at 6PM Eastern Time, and the two months that follow.
library(flipTime) UpdateAt("05-15-2017 18:00:00", us.format = TRUE, time.zone = "America/New_York", units = "months", frequency = 2, options = "snapshot")
When these functions are used, they cause the R Output in which they are located to be re-run, and any dependent code also to be re-run. For example, if you import a data set and have this programmed to update, all analyses that use the data set will automatically update. This means that if you are using R to import your data you can deal with the importing and publishing of the data at the same time (i.e., using one of these functions), whereas if using another method to import the data, you need to take care to both import (via URL, SQL, or the API) and to publish (via R).
Some thought needs to be given when deciding where to place these functions in your document. For example, if your document has two data sets and also imports data through an R Output, you need to ensure that you use one of these functions in each of these three places.
You can find out more about these functions on the wiki.
Automatic data exporting
Sometimes it is helpful to have a document that automatically exports results. For example, you may want to have another Displayr document or another app to automatically import data that has been computed using Displayr. This is described in How to Link Documents in Displayr.
About Tim Bock
Tim Bock is the founder of Displayr. Tim is a data scientist, who has consulted, published academic papers, and won awards, for problems/techniques as diverse as neural networks, mixture models, data fusion, market segmentation, IPO pricing, small sample research, and data visualization. He has conducted data science projects for numerous companies, including Pfizer, Coca Cola, ACNielsen, KFC, Weight Watchers, Unilever, and Nestle. He is also the founder of Q www.qresearchsoftware.com, a data science product designed for survey research, which is used by all the world’s seven largest market research consultancies. He studied econometrics, maths, and marketing, and has a University Medal and PhD from the University of New South Wales (Australia’s leading research university), where he was an adjunct member of staff for 15 years.
Ask a question
If you would like further information on any of the topics mentioned in this article, please get in touch using the form on this page.