Reader small image

You're reading from  Learning Jupyter

Product typeBook
Published inNov 2016
Reading LevelIntermediate
PublisherPackt
ISBN-139781785884870
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Dan Toomey
Dan Toomey
author image
Dan Toomey

Dan Toomey has been developing application software for over 20 years. He has worked in a variety of industries and companies, in roles from sole contributor to VP/CTO-level. For the last few years, he has been contracting for companies in the eastern Massachusetts area. Dan has been contracting under Dan Toomey Software Corp. Dan has also written R for Data Science, Jupyter for Data Sciences, and the Jupyter Cookbook, all with Packt.
Read more about Dan Toomey

Right arrow

Chapter 8. Multiuser Jupyter Notebooks

Jupyter notebooks have the inherent ability to be modified by users as and when the user enters data or makes a selection. However, there is an issue with the standard implementation of the notebook server software that does not account for more than one person working on a notebook at the same time. The notebook server software is the underlying Jupyter software that displays the page and interacts with the user-it follows the directions in your notebook for display and interaction.

A notebook server, really a specialized internet web server, typically creates a new path or thread of execution for each user to allow for multiple users. A problem comes up when a lower level subroutine, used for all instances, does not properly account for multiple users where each has their own set of data.

Note

Some of the coding/installs of this chapter may not work in a Windows environment.

In this chapter, we will do the following:

  • We will give an example of the issue...

Sample interactive notebook


For this chapter, we will use a simple notebook that asks the user for some information and displays other information.

For example, we could have a script such as this (taken from  Chapter 7 , Sharing and Converting Jupyter Notebooks):

from ipywidgets import interact
def myfunction(x):
    return x
interact(myfunction, x= "Hello World ")

The script presents a textbox to the user with the original value of the box containing the "Hello World" string. As the user interacts with the input field and changes the value, the value of the variable x in the script changes accordingly and is displayed on screen. For example, I have changed the value to the letter A:

We can see the multiuser problem if we just open the same page in another browser window (copy the URL, open a new browser window, paste in the URL, and hit Enter)-we get the exact same display pulling up the last checkpoint. The new window should have started with a new script, just prompting you with the...

JupyterHub


Once Jupyter notebooks were shared, it became obvious that the multiuser problem had to be solved. A new version of the Jupyter software was developed, called JupyterHub. JupyterHub was specifically designed to handle multiple users, giving each user their own set of variables to work with. Actually, the system will give each user a whole new instance of the Jupyter software to each user-a brute force approach, but it works.

When JupyterHub starts up, it initiates a hub or controlling agent. The hub will start an instance of a listener or proxy for Jupyter requests. When the proxy gets requests for Jupyter it turns them over to the hub. If the hub decides that this is a new user, it will generate a new instance of the Jupyter server and attach all further interactions between that user and Jupyter to their own version of the server.

Installation

JupyterHub requires Python 3.3 or newer, and we will use the pip3 Python tool to install JupyterHub. You can check the version of Python...

Docker


Docker is another mechanism that can be used to allow multiple users of the same notebook without collision. Docker is a system that allows you to construct sets of applications into an image that can be run in a container. It runs in most environments. Docker allows for many instances of an image to be run in the same machine, but maintains separate address space, so each user of a Docker image has their own instance of the software and their own set of data/variables.

Each image is a complete stack of software necessary to run, for example, a web server, web application(s), API(s), and so on.

It is not a large leap to think of an image of your notebook. The image contains Jupyter server code and your notebook. The result is a completely intact unit that does not share any space with another's instance.

Installation

Installing Docker involves downloading the latest version (the docker.dmg file for a Mac and the EXE install for Windows) and then copying the Docker applications into your...

Summary


In this chapter, we learned how to expose a notebook so that multiple users can use a notebook at the same time. We saw an example of the error occurring and installed a Jupyter server that addresses the problem. We then used Docker to alleviate the issue.

In the next chapter, we will look using Scala in a notebook.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Learning Jupyter
Published in: Nov 2016Publisher: PacktISBN-13: 9781785884870
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Dan Toomey

Dan Toomey has been developing application software for over 20 years. He has worked in a variety of industries and companies, in roles from sole contributor to VP/CTO-level. For the last few years, he has been contracting for companies in the eastern Massachusetts area. Dan has been contracting under Dan Toomey Software Corp. Dan has also written R for Data Science, Jupyter for Data Sciences, and the Jupyter Cookbook, all with Packt.
Read more about Dan Toomey