This article describes how to use Displayr to automatically append new data to an existing data set stored in Dropbox. Specifically, the article contains steps required to set up a system that automatically imports a file from Dropbox to Displayr, adds data to it using Displayr, and then exports the updated file back to Dropbox.
- A Dropbox account.
- A Dropbox Access Token (see How to Create an Access Token for Dropbox).
- An existing data set stored in Dropbox (see How to Add a Data Set file to Dropbox).
- Note: This process only works with .csv, .rda, or .rds data sets.
- Go to Calculation > Custom Code.
- Click on the Page where you want to position the output.
- Update and enter the below R Code:
UpdateEvery(15, units = "minutes", options = "wakeup")
imported = ImportFromDropbox("memorydata.rda", token)
memory = as.integer(mem_used() / 1000000)
new.data = data.frame(time = Sys.time(), memory = memory)
exported = rbind(imported, new.data)
ExportToDropbox(exported, token, "memorydata.rda")
The above code downloads the existing data set file from Dropbox, adds a new line then re-exports the updated file. The process is repeated every 15 minutes as defined in the second line of the code. The wakeup option ensures the process is repeated even if the document is closed.
The following two lines import the existing data. In this example, the amount of memory used by R (in megabytes) is imported and a new row with the time and the memory used is added. Finally, the new data is appended to the existing data and sent back to Dropbox.
You will need to replace the mention of token with your token string. For instance, if your token was ABCDefgh1234 you would need to put "ABCDefgh1234" in place of the token (including the speech marks). Tokens are normally quite long.
How to Create an Access Token for Dropbox
How to Add a Data Set File to Dropbox
How to Get Started With the Displayr API
Article is closed for comments.