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.
- A Displayr document
- OPTIONAL: Updating using Displayr's API or automatic publishing a dashboard requires Server time for private dashboards and API on your account and will consume that time.
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 Data Sets > > 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., Data Sets>> SQL).
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:
- Import the data as a Data Set using Data Sets>> R (the option is to the left of SQL).
- Import the data into an R Output using Calculation > Custom Code.
- Write R code to import the data (e.g., using foreign::read.spss or read.csv). See How to Import a Data Set Using R for more details.
- Use one of the following functions to tell Displayr when to re-run the code: message, UpdateEvery, or UpdateAt.
- 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.
Option 4: Displayr's API
Displayr's API can automatically update and perform some modifications of documents (e.g., creating new tables). Please Note: Updating using Displayr's API requires Server time for private dashboards and API on your account and will consume that time.
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.
When these functions are used, they cause the R Code 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 R Code, 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 at How to Automatically Update Calculations, Variables, and Data Sets Using R.
Please Note: Automated publishing requires Server time for private dashboards and API on your account and will consume that time.
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 automatically import data that has been computed using Displayr. See the method described here: Create a Separate Data Preparation Document.