Sometimes it is useful for dashboards to update in "real-time". Typically, this is where the data is rapidly changing, and the view of the data from one moment is different to the next. The two main situations where real-time updating is relevant are where the data being collected is updating regularly, and where data on actions taken by the company is updated. In this post I explain the various mechanisms for updating Displayr dashboards in 'real-time'.
Real-time >= Every 10 minutes
It's never technically possible for a dashboard to update instantly. Computations take time, albeit small amounts of time. And, the more rapid the updating the more intensive the computer resources. In Displayr, "real-time" means at best, every 10 minutes.
Updating data sets
When data is read in from URLs, SQL, and the Displayr Cloud Drive, there is an option for automatically specifying the regularity of updating of data. When reading in data sets via R, you can also write code to determine when they update.
Updating publication of the dashboard
If you follow the instructions above, you can get your data to update. The next step is to control when the dashboard itself is re-published, as this is required for a viewer to see the updates. This is done via Insert > Utilities > Automatic Updating which inserts an object on the page with options for controlling updating.
There are a few easy-to-make mistakes when using automatic updating.
Automatic publication of documents being manually edited
If you are making manual edits to a document and it is automatically published, it will be automatically published with your incomplete edits revealed to your viewers.
Failure to sync updating
Let's say you have set your data to update every 24 hours. And, you've set your data to republish every 10 minutes. It will republish, but the results will still only change every 24 hours. Or, let's say you kick off automatic publication to occur every Monday, but you have automatic updating of the data on Wednesday. The published document will re-publish on Monday, but only showing the data up until last Wednesday.
Manual R Outputs containing UpdateAt and UpdateEvery
If you are using UpdateAt or UpdateEvery in your write R code these will cause the R code to be re-run, even if Automatic is not checked on the R Output.
Calculations without dependencies
The image below seems to show some impossible results. The automatic updating has occurred at 9:23, but the time stamp above is showing 9:16, so it hasn't actually updated. How has this happened? The code for computing the time stamp at the top is paste("Time where this server is located (somewhere East Coast USA)\n", format(Sys.time(), "%a %b %d %X %Y")) The key thing to note about this code is that it does not depend on anything else. Consequently, once it is computed there is nothing to tell it to recompute, so without doing something else, it will never update.
The fix for this problem is to refer to the automatic updating directly in the code, as in the example in the next section. What happens here is that whenever an R Output is referring to something that updates, it itself updates, and, and thus anything that refers to it will also update. As automatic.updating isn't used, it has no effect other than to trigger the calculation.
Consider asking a computer to calculate 1+1. There are two principal ways that a computer can give you the answer. One is it can compute the answer. The other, is it can search to see if it has previously answered the question, and return that result. This is known as caching and it is very widespread. It's very common that things on the internet are cached, as it both reduces computing resources and network load (as it can be cached near the end viewer). If, for example, the time stamp below is not correct within 10 minutes, that is due to caching. (But, keep in mind the effect of time zones!).
A page needs to be told to update
If you are looking at a page in Displayr in your browser, you will not see the results update until something happens to make the screen refresh. Like what?
- You can press the Refresh button in your browser
- If Displayr has fallen asleep, when it wakes it will update.
- Anything that performs a calculation on the page (e.g., using a filter).