This article describes how to link two Displayr Documents. More specifically, the article describes how to move data from one document (source document) to another document (destination document) using Dropbox.
Requirements
- Dropbox Access Token (see: How to Create an Access Token for Dropbox).
- Two Displayr Documents, a source document, and a destination document.
- A Calculation Output consisting of data you wish to move from one document to another.
Please note this requires the Data Stories module or a Displayr license.
Method - creating and exporting the R Output data
- Open your source document.
- In Displayr select Calculation > Custom Code and click on the Page where you want to position the output.
- Link the Calculation Output to the data you wish to move to another document. This can be an object of any kind as long as it's presented as a Calculation Output. Note, most analyses in Displary are presented as a Calculation Output using R Code.
- Add the following two lines of code anywhere in your R Code:
library(flipTime)
The above code tells Displayr to update the Calculation if it's older than one week when the document is open, or if the object is used by another object.
UpdateEvery(1, "weeks")
Alternatively, you can use the following code and specify the first update time and date:library(flipTime)
UpdateAt("30-11-2017 18:00:00", time.zone = "Europe/Madrid", units = "months", frequency = 1 - With the Calculation Output still selected go to the object inspector > Properties > GENERAL > Name and make a note of the name.
- Create another Calculation Output by selecting Calculation > Custom Code and clicking on the Page where you want to position the output. Alternatively, select the output and select Copy > Copy Name from the toolbar.
- Update and input the below R Code:
library(flipAPI)
You will need to replace the mention of object_name with the name of your Output (see step 6) and the 'dropbox access token' mention with your token. The reexport.seconds argument specifies the frequency of exporting the object. In the above code, it's set to every 604800 seconds (i.e. 1 week)
ExportToDropbox(object_name, 'dropbox access token', reexport.seconds = 604800) - Check the Automatic checkbox.
- Select Calculate.
You should be able to see a file called <object>.rds in the Dropbox folder associated with the access token used in the code.
Method - importing the R Output data
- Open your destination document.
- Select Calculation > Custom Code and click on the Page where you want to position the output.
- Update and input the below R Code:
library(flipAPI)
You will need to replace the mention of object.rds with the name of the file saved in your Dropbox folder, and the 'dropbox access token' mention with your token.
object.copy = ImportFromDropbox('object.rds', 'dropbox access token') - Check the Automatic checkbox.
- Select Calculate.
Displayr will import the R Output from your source document. Once done you can use the Calculation Output in the same way as any other Calculation Outputs created in the document itself.
Next
How to Create an Access Token for Dropbox
How to Add a Data Set file to Dropbox
How to Import Data from Dropbox
How to Automatically Append Data to an Existing Data Set Stored in Dropbox
How to Get Started with the Displayr API
How to Merge Data Files Using the Displayr API