It is sometimes possible to compute results ahead of time and use these pre-computed results. This article contains four worked examples:
- Example 1: Pre-compute table(s)
- Example 2: Pre-compute pages
- Example 3: Pre-compute all constructed variables in a document
- Example 4: Run Slow Data Queries, Calculations, and Extracts When Users Aren't Using a Document
Example 1: Pre-compute table(s)
A standard way of adding interactivity in Displayr is to create outputs and then provide list boxes or combo boxes for the user to filter outputs (for example, see How to Create a List Box Filter). With such a design, the dependency graph typically looks like the one below. In this example:
- Combo box presents the user with five options.
- When the user changes the option in the combo box, the R variable Campsight Filter is recomputed, which is based on the Site variable. This takes 0.38 seconds.
- The table, which summarizes the data in How satisfied are you with... is updated. This takes no time.
- Then, the visualization is updated, which takes 1.97 seconds.
A different way of creating the same result is to have a table showing satisfaction by the Site variable. Then, the control is used to select columns from that pre-computed table, using the setting for the visualization of Inputs > COLUMN MANIPULATION > Select columns to show by. Note that:
- The dependency graph is shorter and doesn't include any filtering.
- The table now takes 0.02 seconds to compute. However, this does not affect the user, as the table can be computed before the user looks at the dashboard (as it doesn't depend on anything the user doesn't).
- The 0.38 seconds taken to compute the filter are no longer required.
- The finalization is still the slowest thing to compute. It is a bit faster in the second example, but this is a coincidence (using parallel processing causes calculation times to vary).
- This is a simple example; it's only saving 0.36 seconds, which isn't much on its own. However, if you have many similar outputs, it quickly adds up.
Example 2: Pre-compute pages
Entire pages can be pre-computed. To do that, you can:
- Create a page.
- Select everything on the page and apply a filter.
- Duplicate the page and change the filter.
- Create a content page, where you can add hyperlinks to each page. In the below example, each country flag acts as a hyperlink to a country-specific page. With some creativity, it can appear as an interactive dashboard, as in the example below.
Example 3: Pre-compute all constructed variables in a document
The basic idea here is that you split your document into two: one for data preparation (e.g., coding, recoding) and a separate document for reporting. See Creating a Separate Data Preparation Document.
Example 4: Run Slow Data Queries, Calculations, and Extracts When Users Aren't Using a Document
In some studies, some of the results are known to change at different points in time. Most commonly, with tracking studies and retail sales databases, the results are refreshed every week, month, or quarter. For more information, see Run Slow Data Queries, Calculations, and Extracts When Users Aren't Using a Document.