{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Jupyter-first courses: Section 2 (What)\n", "\n", "Lorena A. Barba, April 2019" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Jupyter for Teaching and Learning\n", "\n", "## What is Jupyter?\n", "\n", "Project Jupyter is a broad collaboration that develops open-source tools for interactive and exploratory computing. The tools include: IPython, the Jupyter Notebook, Jupyter Hub, and an ecosystem of extensions contributed by a large community.\n", "\n", "The Jupyter Notebook is an application for creating interactive computational narratives. It has exploded in popularity, fueled by its adoption as the favorite environment for data science. \n", "\n", "On May 2nd, 2018, the Association for Computing Machinery (ACM) announced that Jupyter was being awarded the prestigious ACM Software System Award. Past recipients of this award include: Unix, TeX, the World Wide Web, Java, and the GCC compiler. \n", "The [ACM press release for the award](https://www.acm.org/media-center/2018/may/technical-awards-2017) says of Jupyter that it has “become a de facto standard for data analysis in research, education, journalism and industry.” \n", "\n", "In the last three years, industry adoption of Jupyter took hold, with new products by Google (Cloud DataLab), Microsoft (AzureML, HDInsight), Intel (Trusted Analytics Platform), and IBM (IBM Watson Studio).\n", "\n", "In April 2018, the number of publicly available Jupyter notebooks on GitHub surpassed [two million](https://twitter.com/parente/status/981725895655411714?s=20), and the number crossed the three million mark in [November](https://twitter.com/parente/status/1058727026557939712?s=20).\n", "\n", "Jupyter is also skyrocketing as a platform to teach computing and data science. [A Gallery of Interesting Jupyter Notebooks](https://github.com/jupyter/jupyter/wiki/A-gallery-of-interesting-Jupyter-Notebooks) lists entire books, lessons or courses using Jupyter for introductory programming, statistics, machine learning, mathematics, physics, signal processing, linguistics, chemistry, text mining, biomechanics, and more.\n", "\n", "The Jupyter Notebook is a browser-based application that allows instructors to create and share documents with live equations, visualizations, and code. Jupyter Notebooks help students get started with analysis faster and provide a standardized, replicable analytic environment for shared exploration and research through interactive computing.\n", "\n", "The Berkeley Data Science program for undergraduates, which began in Fall 2015, is entirely Jupyter-based. More than 1,000 first-year students are currently in the program, after a rapid escalation from the pilot course with 100 students. The article [The Course of the Future and the Technology Behind It](https://data.berkeley.edu/news/coursefuture) explains how Jupyter enabled the scaling out of the program: through “browser-based computation, avoiding the need for students to install software, transfer files, or update libraries.” This is powered by JupyterHub, a cloud-hosted version of Jupyter that universities can deploy to offer a common computational environment for all instructors and students.\n", "\n", "The precursor of Jupyter was IPython, created by Fernando Pérez starting 2001. He says: \n", "> The role of Jupyter is to give students, researchers, journalists or industry engineers tools that give them a coherent handle on the entire process of computational exploration and discovery. We have built it so the same tools are used for individual data analysis or to create a published article, course or book." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Working in Jupyter\n", "\n", "Several things may be counter-intuitive to you at first. For example, most people are used to launching apps in their computers by clicking some icon: this is the first thing to \"unlearn.\" Jupyter is typically launched from the _command line_ (like when you launched IPython). If you are using the Anaconda distribution (highly recommended), you can also open Jupyter from the Anaconda Navigator in the more familiar way of clicking an icon.\n", "\n", "On a Jupyter notebook, you have two types of content—code and markdown—that handle a bit differently. The fact that your browser is an interface to a compute engine (called \"kernel\") leads to some extra housekeeping (like shutting down the kernel). But you'll get used to it pretty quick!\n", "\n", "### Start Jupyter\n", "\n", "The standard way to start Jupyter is to type the following in the command-line interface:\n", "\n", "`jupyter notebook` \n", "\n", "Hit enter and tadah!!\n", "After a little set up time, your default browser will open with the Jupyter app. It should look like in the screenshot below, but you may see a list of files and folders, depending on the location of your computer where you launched it.\n", "\n", "##### Note:\n", "\n", "Don't close the terminal window where you launched Jupyter (while you're still working on Jupyter). If you need to do other tasks on the command line, open a new terminal window.\n", "\n", " \n", "#### Screenshot of the Jupyter dashboard, open in the browser.\n", "\n", "\n", "To start a new Jupyter notebook, click on the top-right, where it says **New**, and select `Python 3`. Check out the screenshot below.\n", "\n", " \n", "#### Screenshot showing how to create a new notebook.\n", "\n", "A new tab will appear in your browser and you will see an empty notebook, with a single input line, waiting for you to enter some code. See the next screenshot.\n", "\n", " \n", "#### Screenshot showing an empty new notebook.\n", "\n", "The notebook opens by default with a single empty code cell. Try to write some Python code there and execute it by hitting `[shift] + [enter]`." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Notebook cells\n", "\n", "The Jupyter notebook uses _cells_: blocks that divide chunks of text and code. Any text content is entered in a *Markdown* cell: it contains text that you can format using simple markers to get headings, bold, italic, bullet points, hyperlinks, and more.\n", "\n", "Markdown is easy to learn, check out the syntax in the [\"Daring Fireball\"](https://daringfireball.net/projects/markdown/syntax) webpage (by John Gruber). A few tips:\n", "\n", "* to create a title, use a hash to start the line: `# Title`\n", "* to create the next heading, use two hashes (and so on): `## Heading`\n", "* to italicize a word or phrase, enclose it in asterisks (or underdashes): `*italic*` or `_italic_`\n", "* to make it bold, enclose it with two asterisks: `**bolded**`\n", "* to make a hyperlink, use square and round brackets: `[hyperlinked text](url)`\n", "\n", "Computable content is entered in code cells. We will be using the IPython kernel (\"kernel\" is the name used for the computing engine), but you should know that Jupyter can be used with many different computing languages. It's amazing.\n", "\n", "A code cell will show you an input mark, like this: \n", "\n", "`In [ ]:`\n", "\n", "Once you add some code and execute it, Jupyter will add a number ID to the input cell, and produce an output marked like this:\n", "\n", "`Out [1]:`\n", "\n", "##### A bit of history: \n", "\n", "Markdown was co-created by the legendary but tragic [Aaron Swartz](https://en.wikipedia.org/wiki/Aaron_Swartz). The biographical documentary about him is called [\"The Internet's Own Boy,\"](https://en.wikipedia.org/wiki/The_Internet%27s_Own_Boy) and you can view it in YouTube or Netflix. Recommended!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Interactive computing in the notebook\n", "\n", "Look at the icons on the menu of Jupyter (see the screenshots above). The first icon on the left (an old floppy disk) is for saving your notebook. You can add a new cell with the big **+** button. Then you have the cut, copy, and paste buttons. The arrows are to move your current cell up or down. Then you have a button to \"run\" a code cell (execute the code), the square icon means \"stop\" and the swirly arrow is to \"restart\" your notebook's kernel (if the computation is stuck, for example). Next to that, you have the cell-type selector: Code or Markdown (or others that you can ignore for now).\n", "\n", "You can test-drive a code cell by writing some arithmetic operations. Like we saw in our first lesson, the Python operators are:\n", "```python\n", " + - * / ** % //\n", "```\n", "\n", "There's addition, subtraction, multiplication and division. The last three operators are _exponent_ (raise to the power of), _modulo_ (divide and return remainder) and _floor division_.\n", "\n", "Typing `[shift] + [enter]` will execute the cell and give you the output in a new line, labeled `Out[1]` (the numbering increases each time you execute a cell).\n", "\n", "##### Try it!\n", "\n", "Add a cell with the plus button, enter some operations, and `[shift] + [enter]` to execute." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Edit mode and Command mode\n", "\n", "Once you click on a notebook cell to select it, you may interact with it in two ways, which are called _modes_. Later on, when you are reviewing this material again, read more about this in Reference 1. \n", "\n", "**Edit mode:**\n", "\n", "* We enter **edit mode** by pressing `Enter` or double-clicking on the cell.\n", "\n", "* We know we are in this mode when we see a green cell border and a prompt in the cell area.\n", "\n", "* When we are in edit mode, we can type into the cell, like a normal text editor.\n", "\n", "\n", "**Command mode:**\n", "\n", "* We enter in **command mode** by pressing `Esc` or clicking outside the cell area.\n", "\n", "* We know we are in this mode when we see a grey cell border with a left blue margin.\n", "\n", "* In this mode, certain keys are mapped to shortcuts to help with\n", " common actions.\n", "\n", "\n", "You can find a list of the shortcuts by selecting `Help->Keyboard Shortcuts`\n", "from the notebook menu bar. You may want to leave this for later, and come back to it, but it becomes more helpful the more you use Jupyter." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### How to shut down the kernel and exit\n", "\n", "Closing the browser tab where you've been working on a notebook does not immediately \"shut down\" the compute kernel. So you sometimes need to do a little housekeeping.\n", "\n", "Once you close a notebook, you will see in the main Jupyter app that your \n", "notebook file has a green book symbol next to it. You should click in the box at the left of that symbol, and then click where it says **Shutdown**. You don't need to do this all the time, but if you have a _lot_ of notebooks running, they will use resources in your machine.\n", "\n", "Similarly, Jupyter is still running even after you close the tab that has the Jupyter dashboard open. To exit the Jupyter app, you should go to the terminal that you used to open Jupyter, and type `[Ctrl] + [c]` to exit." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Nbviewer\n", "\n", "[Nbviewer](http://nbviewer.jupyter.org/) is a free web service that allows you to share static versions of hosted notebook files, as if they were a web page. If a notebook file is publicly available on the web, you can view it by entering its URL in the nbviewer web page, and hitting the **Go!** button. The notebook will be rendered as a static page: visitors can read everything, but they cannot interact with the code. " ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.8" } }, "nbformat": 4, "nbformat_minor": 2 }