Sometimes the data used in a document takes a long time to extract (e.g., when extracted by a SQL query, an API, or an integration). It's also possible that some calculations may be slow (e.g., hierarchical Bayesian calculations). Where these slow operations occur while users are using a Displayr document, the result is that the document slows down.
A solution to this problem is to schedule these slow operations to occur when the users are not using the document.
Worked example
The code below obtains the last five years of stock market prices for Microsoft. While this example is fast to compute, it's used as a surrogate for a more expensive calculation (e.g., a slow SQL query).
library(quantmod)
library(reshape2)
data <- new.env()
suppressWarnings(getSymbols("MSFT",
env = data,
from = seq(as.Date(Sys.Date()), length = 2, by = "-5 years")[2],
to = Sys.Date(),
auto.assign = TRUE))
all.data <- data[[ls(data)[1]]]
stock.prices <- data.frame(all.data)
- From the object inspector, go to Data > Schedule.
- Click + to create a new schedule.
- A new pane will open to the left. Update Start to At.
- Update the time to 1:00 AM.
The output connected to this schedule will appear in the Schedules pane just under the schedule:
You can also see it in the object inspector when the output is selected: