This article describes how to create automatically updating text boxes, where the text updates when the data changes, using R code.
Requirements
A Displayr document.
Method 1 - Showing the date
- From the toolbar, go to Calculation > Custom Code.
- Paste the following code into the R CODE box in the object inspector:
format(Sys.time())
3. Press Calculate and you will now see the date in the universal time zone:
Method 2 - Showing the time
- From the toolbar, go to Calculation > Custom Code.
- Paste the following code into the R CODE box in the object inspector:
format(Sys.time(),'%A, %B %d, %Y %H:%M:%S')
3. Press Calculate and you will now see the date and time in the universal time zone:
Method 3 - Creating more complicated text
You can embed the date and time into a sentence:
- From the toolbar, go to Calculation > Custom Code.
- Paste the following code into the R CODE box in the object inspector:
paste0("Today's date and time is: ",
format(Sys.time(),'%A, %B %d, %Y %H:%M:%S'),
".")
3. Press Calculate and you will now see the date and time in the universal time zone embedded into a sentence:
You can customize the text by updating "Today's date and time is: " to the text that you desire.
Next
How to Work with Date Ranges Using R
How to Work with Aggregated Dates Using R