Interactive R Notebooks with Jupyter and SageMathCloud

Posted on June 20, 2015 by

17


JupyterDemo

The Jupyter Notebook interface allows users to seamlessly mix code, output, and markdown commentary all in the same document.  Sound a bit like R Markdown? The difference is that in a Jupyter Notebook, you execute the code right in the browser and view everything in the same visual view.

Jupyter, formerly known as the IPython Notebook, has a rich ecosystem, especially among Python users. Nature News recently featured Jupyter and its benefits for reproducible research and collaboration; Github, which automagically renders Jupyter notebook files on their website, has a gallery featuring a wide variety of cool static renderings of notebooks.

The name Jupyter (JUlia, PYThon, R) shows that the project has ambitions outside of its Python homeland. But so far, I've seen very little discussion in the R community, besides for Tony Hirst's recent musings on synergies between R Markdown and Jupyter.. R basically works in Jupyter, though it has nothing like the support that knitr now has for shiny and a variety of other fancier interactive R features in R Markdown and Rnw files.

It's still pretty cool to be able to see the output & change the code together in Jupyter, though. First, I recommend checking out the demo on the Jupyter web site. You can then click on the
"Welcome to R" demo and play around with the code:

R_welcome_Jupyter

To update the output from a compute cell, you can press CTRL + ENTER or simply press the ▶ on the upper toolbar.  SHIFT + ENTER runs the code and selects the next cell to make it easy to traverse down the document. Note that Jupyter also has nice Tab-completion, menus, and a host of other features! You can also upload or start your own files.

But, this is just a temporary server.  How can you bring Jupyter into your workflow?  You can install Jupyter and the R Kernel locally on your computer, which is relatively straightforward on Linux but looks like a pain on any other OS.

Another way: there are a few commercial cloud services that host Jupyter notebooks, and the one I like right now is SageMathCloud. The Sage Math project has come a long way on its goals of developing open-source math and collaboration tools, and I see a host of fascinating features on this app, such as course management tools for classroom use, collaborative editing and live video chat alongside a project & file system for managing Jupyter notebooks and Sage Math worksheets, and the ability to open multiple notebooks in different tabs:

Sage_Jupyter

 

I have been startled both by the robustness and activity of the development of Jupyter, and the relatively little discussion from the R community.  Let's get into Jupyter and see what we can create, and how we can shape the future of this highly promising tool for collaborative, reproducible data science & statistics.

Acknowledgment: Pictured notebooks are based on Rmd files by Yadira Peralta (top) and Kyle Nickodem (bottom).  These were originally created for presentations for the Ed Psych Computing Club at the University of Minnesota.

Posted in: Codespeak, R