Shiny + archivist = reproducible interactive exploration


Shiny is a great tool for interactive exploration (and not only for that). But, due to its architecture, all objects/results that are generated are stored in a separate R process so you cannot access them easily from your R console.

In some cases you may wish to retrieve a model or a plot that you have just generated. Or maybe just wish to store all R objects (plots, data sets, models) that have been ever generated by your Shiny application. Or maybe you would like to do some further tuning or validation of a selected model or plot. Or maybe you wish to collect and compare all lm() models ever generated by your app? Or maybe you would like to have an R code that will recover given R object in future.

So, how to do this?

Here I am going to present a solution based on a combination of archivist + shiny.
Archivist is a package for management of R objects. It allows you to create a repository (local folder or git repo) and push all interesting R objects to it. Each object will be stored along with its metadata. Each object will get it’s unique key, i.e. md5hash.
Then you or your collaborators may access these objects from any R process, local or remote.

So how to extract an R object from shiny to your local R console?
1. In the app create an archivist repository with archivist::createLocalRepo().
2. In the app push selected objects from shiny to this repository with archivist::saveToLocalRepo().
3. In the app print links to these objects somewhere in the shiny UI.
4. In the console, read the R object from the repository with archivist::aread().

Below you will find an example shiny application, that creates a repo and stores all plots in this repo. Also it’s printing hooks to selected objects in a figure caption.

In order to read a single R object from default repo you can use aread() function, like

Since the repository stores all meta data related to stored objects, you may ask for R objects that match some pattern. The instruction below downloads all R objects of the class ‚gg’ and plot them all.

If you wish to learn more about the archivist package, come to the useR 2016 archivist talk or see the archivist webpage.

Dodaj komentarz

Twój adres email nie zostanie opublikowany. Pola, których wypełnienie jest wymagane, są oznaczone symbolem *