R + binder = interactive Jupyter notebooks in the cloud

[This article was first published on R on FeelML, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Have you ever found a GitHub repository with an interesting R package?
Probably yes.
How cool would it be to try it out without having to deal with installation and dependencies?

Fortunately, it is possible thanks to the BinderHub – the server technology that turns computational material (e.g. Jupyter Notebook) into interactive computational environments in the cloud.
Here you can see an example of such an interactive notebook. Loading may take around 15 seconds.

How to use it?

Using these interactive notebooks is very convenient because all you have to do is just look for the badge like this one: and click on it. You can modify chunks with code and re-run them by pressing Ctrl+Enter or Shift+Enter.

Let’s learn more about the Binder.

How does it work?

It is best to let the authors describe Binder themselves. Below you can read a part of the Binder documentation.

Binder makes it simple to generate reproducible computing environments from a Git repository. Binder uses the BinderHub technology to generate a Docker image from this repository. The image will have all the components that you specify along with the Jupyter Notebooks inside. You will be able to share a URL with users that can immediately begin interacting with this environment via the cloud. Binder’s goal is to enable as many analytic workflows as possible.

Now let’s see how to build a Binder repository.

Turn your GitHub repository into a collection of interactive notebooks

In the Binder documentation, you will find detailed and extended instructions. Here, I will show a minimal example of the basic configuration in three easy steps.

  1. You need a GitHub repository with at least one Jupyter notebook.
    If you do not have Jupyter installed on your computer, you can create a notebook online. Just chose the Try Jupyter with R option on the Jupyter website. However, it may be difficult to load some of the packages, so I suggest using the Jupyter installed locally on your computer.

  2. Create configuration files in your GitHub repository.
    Those files specify the requirements for building a Binder repository. They may be placed in the repository’s root or in a binder/ folder.
    Here you’ll find a toy example with configuration files. In your repository you should have at least two of them:

  • runtime.txt with specified MRAN snapshot that is formatted like:

r-<YYYY>-<MM>-<DD>

The example file content: r-2018-06-01

  • install.R that will be executed during the build and is used to install libraries. The example file content:
install.packages("auditor")
install.packages("DALEX")
install.packages("randomForest")

If your GitHub repository contains an R package and is integrated with Travis CI, don’t forget to exclude configuration files from the build by adding them to .Rbuildignore. Otherwise, you’ll get a warning and notes during the package check.

  1. Building and launching a Binder repository

Now, you’re ready to launch your Binder repository. To do this, you need to visit MyBinder.org.

On the MyBinder.org, in the How it works section, you will find clear instructions on how to build and launch a Binder repository.

In short, you should provide a URL or a GitHub repository name. Optionally, you can specify a path to a notebook file which will be opened in your browser after building. The building may take some time. It depends on the packages that need to be installed. Afterward, the binder will build a Docker image and then will automatically send you to a live Jupyter session connected to your repository.

Now you can finally generate a binder badge !

To leave a comment for the author, please follow the link and comment on their blog: R on FeelML.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)