Introduction
This article describes how to force outputs to recalculate on a given schedule in your Displayr document. Displayr automatically recalculates outputs if any of their dependencies change, see Viewing Dependency Graphs to Understand Calculations and Performance, but sometimes you may wish to update an R output(s) that don't have dependencies within Displayr. This can be useful for outputs that pull in data from other sources, such as Twitter feeds, google trends, stock prices, and other custom outputs.
Requirements
A Displayr document with an R -based output you'd like to be recalculated at a set schedule.
Method
- Go to Anything > Report > Automatic Updating.
- In the object inspector, enter the appropriate options:
-
Update period - The time unit for regular updates.
-
Frequency - The multiple of the Update period for regular updating.
-
Start date and time - The date and time of the first update in the format dd-mm-yyyy hh:mm or mm-dd-yyyy hh:mm.
-
US date format - Whether the Start date and time is expressed in US format i.e. mm-dd-yyyy hh:mm.
-
Time zone - An optional time zone for the Start date and time, or else the default of UTC applies. The format must be Continent/City, eg America/Los_Angeles. See Wikipedia for a list of time zones.
-
Update exported documents - Whether exported documents that refer to the data should also be updated regularly. This includes publishing your document.
-
- Click Calculate if the output doesn't calculate automatically.
- Select the R-based output that you'd like to recalculate on a set schedule.
- In the Properties > R CODE of the item you would like recalculated, click into the R CODE and add a line at the top referencing the Automatic Updating output you just created. You can do this two ways by:
- Clicking on the Automatic Updating widget to insert its name into the code.
- Or by copying and pasting in the name from the Properties > GENERAL > Name of the Automatic Updating widget.
As a basic example, using the following code in a Calculation will get recalculated on the schedule and display the date/time of recalculation:
#reference the automatic updating widget
automatic.updating
#print the date/time recalculated
format(Sys.time(),"%Y-%m-%d %H:%M")
- Clicking on the Automatic Updating widget to insert its name into the code.
Keep in mind any other items in your document that depend on the output being recalculated in step 5 will be recalculated automatically and do not need their R code amended.
See Also
How to Automatically Republish a Dashboard
How to Create Dashboards with Real-Time Updating
How to Automatically Update Dashboards in Displayr
How to Automatically Update Calculations, Variables and Data Sets Using R