Book Image

Jupyter Cookbook

By : Dan Toomey
Book Image

Jupyter Cookbook

By: Dan Toomey

Overview of this book

Jupyter has garnered a strong interest in the data science community of late, as it makes common data processing and analysis tasks much simpler. This book is for data science professionals who want to master various tasks related to Jupyter to create efficient, easy-to-share, scientific applications. The book starts with recipes on installing and running the Jupyter Notebook system on various platforms and configuring the various packages that can be used with it. You will then see how you can implement different programming languages and frameworks, such as Python, R, Julia, JavaScript, Scala, and Spark on your Jupyter Notebook. This book contains intuitive recipes on building interactive widgets to manipulate and visualize data in real time, sharing your code, creating a multi-user environment, and organizing your notebook. You will then get hands-on experience with Jupyter Labs, microservices, and deploying them on the web. By the end of this book, you will have taken your knowledge of Jupyter to the next level to perform all key tasks associated with it.
Table of Contents (17 chapters)
Title Page
Copyright and Credits
Packt Upsell

Installing Jupyter on a server

The term server has changed over time to mean several things. We are interested in a machine that will have multiple users accessing the same software concurrently. Jupyter Notebooks can be run by multiple users. However, there is no facility to separate the data for one user from another. Standard Jupyter installations only expect and account for one user. If we have a Notebook that allows for data input from the user, then the data from different users will be intermingled in one instance and possibly displayed incorrectly.

How to do it...

See the following example in this section.

Example Notebook with a user data collision

We can see an example of a collision with a Notebook that allows for data entry from a user and responds with incorrect results:

  • I call upon an example that I have used elsewhere for illustration. For this example, we will use a simple Notebook that asks the user for some information and changes the display to use that information:
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 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—which is incorrect. We expected the new window to start with a new script, just prompting us with the default Hello World message. However, since the Jupyter software expects only one user, there is only one copy of the variable x; thus, it displays its value A.

We can have a Notebook server that expects multiple users and separates their instances from each other without the annoying collisions occurring. A Notebook server includes the standard Jupyter Notebook application that we have seen, but a server can also include software to distinguish the data of one user from another. We'll cover several examples of this solution in Chapter 8, Multiuser Environments.