This article describes how to create a text box to show the date and time of a particular action, such as updating data or republishing a dashboard. The R code will give the date and time of when the R Calculation was last ran. Items in the Report only recalculate when something they are dependent on is updated. In order to trigger the Calculation to rerun, you will need to either reference a variable in your data set or add it to a Schedule.
Method 1 - Show Date when Data Updates
- Identify a variable in your data set or an item in your Report that you want to peg the Date shown too and notice the object inspector > General > Name. We'll use a variable called Age.
- From the toolbar or right click menu in the Report pane, go to Calculation
> Custom Code.
- Paste the following code into the R CODE box in the object inspector and change Age to your variable/item name:
#reference any variable in your data set or item in your Report
Age
#after the variable/item is updated the current date is calculated
format(Sys.time())
3. Press Calculate and you will now see the date in the universal time zone:
4. [Optional]: See below for other examples of how to show the date/time in the output.
Method 2 - Show the Most Recent Date a Schedule Ran
- Setup a Schedule in Displayr, see How to Set Up Schedules in Displayr to setup a schedule to run at a given frequency.
- From the toolbar or right click menu in the Report pane, go to Calculation
> Custom Code.
- Paste the following code into the R CODE box in the object inspector:
#after the variable/item is updated the current date is calculated
format(Sys.time())
3. Press Calculate and you will now see the date in the universal time zone:
4. [Optional]: See below for other examples of how to show the date/time in the output.
5. Add this R Calculation to a schedule to rerun it at a given frequency via its object inspector > General > Schedule dropdown.
6. Recalculate.
Additional Notes
You can further customize how your date and time show up in the output using R code:
- Add other formats within the '' in the format() function, see here for all the options. For example:
format(Sys.time(),'%A, %B %d, %Y %H:%M:%S')
- Add additional text to the output using the paste() function. For example:
paste0("The data was last updated: ", format(Sys.time(),'%A, %B %d, %Y %H:%M:%S'),".")
Next
How to Work with Date Ranges Using R
How to Work with Aggregated Dates Using R