{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "hC-731NWXAnQ" }, "source": [ "# JupyterLab" ] }, { "cell_type": "markdown", "metadata": { "id": "3rIfwtTKpQLf" }, "source": [ "---" ] }, { "cell_type": "markdown", "metadata": { "id": "MkdbWkKzfegV", "jp-MarkdownHeadingCollapsed": true, "tags": [] }, "source": [ "## Overview\n", "\n", "JupyterLab is a popular web application on which users can create and write their Jupyter Notebooks, as well as explore data, install software, etc. This section will introduce the JupyterLab interface and cover details of JupyterLab Notebooks.\n", "\n", "1. Set Up\n", "2. The JupyterLab Interface\n", "3. Running JupyterLab Notebooks" ] }, { "cell_type": "markdown", "metadata": { "id": "yt-WtTrcpRpo" }, "source": [ "## Prerequisites\n", "| Concepts | Importance | Notes |\n", "| --- | --- | --- |\n", "| [Getting Started with Jupyter](getting-started-jupyter) | Helpful | |\n", "| [Installing and Running Python: Python in Jupyter](https://foundations.projectpythia.org/foundations/jupyter.html) | Helpful | |\n", "\n", "- **Time to learn**: 50 minutes" ] }, { "cell_type": "markdown", "metadata": { "id": "nvLyiIa8pTI5" }, "source": [ "---" ] }, { "cell_type": "markdown", "metadata": { "id": "eRjK14BjeQXA", "tags": [] }, "source": [ "## Set Up\n", "\n", "To launch the JupyterLab interface in your browser, follow the instructions in [Installing and Running Python: Python in Jupyter](https://foundations.projectpythia.org/foundations/jupyter.html).\n", "\n", "If, instead, you want to follow along using a provided remote JupyterLab instance, launch this notebook via [Binder](https://mybinder.org/) using the launch icon at the top of this page,\n", "\n", "![Binder Launch](../images/binder-highlight.png \"Binder launch button location\")\n", "\n", "and follow along from there! If launching Binder, take note of the `Launcher` tab in the upper-left (see interface below). Click there to find yourself in the same interface moving forward, and feel free to refer back to this tab to follow along." ] }, { "cell_type": "markdown", "metadata": { "id": "Qe2fbSa2gS2X" }, "source": [ "## The JupyterLab Interface\n", "\n", "Go to your browser and take a look at the JupyterLab interface.\n", "\n", "With a base installation of JupyterLab your screen should look similar to the image below.\n", "\n", "Notice:\n", "- The **Menu Bar** at the top of the screen, containing the typical dropdown menus: \"File\", \"Edit\", \"View\", etc.\n", "- Below that is the **Workspace Area** (currently contains the Launcher).\n", "- The **Launcher** is a quick shortcut for accessing the Console/Terminal, for creating new Notebooks, or for creating new Text or Markdown files.\n", "- On the left is a **Collapsible Sidebar**. It currently contains the File Browser, but you can also select the Running Tabs and Kernels, the Table of Contents, and the Extensions Manager.\n", "- Below everything is the **Information Bar**, which is context sensitive. We will touch on this more.\n", "\n", "![Interface](../images/interface_labeled.png)\n", "\n", "We will now take a closer look at certain aspects and features of the JupyterLab Interface." ] }, { "cell_type": "markdown", "metadata": { "id": "zpDZFM3ngsY6" }, "source": [ "### Left Sidebar\n", "\n", "The Collapsible Left Sidebar is open to the **File Browser Tab** at launch. Clicking the File Browser Tab will collapse the sidebar or reopen it to this tab.\n", "- Within this tab, you will see the \"+\" button, which allows you to create a new launcher. \n", "- Next to that is the \"+ folder\" button which allows you to create a new folder that then appears below \"Name\" in the contents of your directory. Double click the folder to enter it, right click the folder for options, or press the \"root folder\" icon to return to the root directory. The root directory is the directory from which JupyterLab was launched. You cannot go above the root directory. \n", "- The \"upload\" button (looks like an arrow pointing up) allows you to upload files to the current folder. \n", "- The \"refresh\" button refreshes the File Browser.\n", "\n", "Below the File Browser Tab is the **Running Tabs and Kernels Tab**. Currently, this tab doesn't have much in it. We will revisit this when we have running kernels. Remember that Kernels are background processes, so closing a tab (Terminal or Notebook) doesn’t shut down the kernel. You have to do that manually. \n", "\n", " \n", "\n", "\n", "The **Table of Contents Tab** is auto-populated based on the headings and subheadings used in the Markdown cells of your notebook. It allows you to quickly jump between sections of the document.\n", "\n", " \n", "\n", "Last is the **Extensions Manager Tab** where you can customize or enhance any part of JupyterLab. These customizations could pertain to themes or keyboard shortcuts, for example. We will not be covering JupyterLab extensions, but you can read more about them [here](https://jupyterlab.readthedocs.io/en/stable/user/extensions.html).\n", "\n", "" ] }, { "cell_type": "markdown", "metadata": { "id": "1WPljwIRg1KH" }, "source": [ "### Terminals\n", " \n", "Let’s select the Running Tabs and Kernels Tab in the Left Sidebar and see how it changes when we've used the Launcher.\n", "\n", "Open a Terminal in the Launcher. It should look very similar to the desktop terminal that you initially launched JupyterLab from, but is running from within JupyterLab, within your existing Conda environment, and within the directory you launched JupyterLab from (the same root folder shown in the File Browser Tab). Notice that there is now a Terminal listed in the Running Terminals Tab.\n", "\n", "In the terminal you can use your usual terminal commands. For example, in the terminal window, run: \n", "\n", "```\n", "$ mkdir test\n", "```\n", "\n", "Select the File Browser Tab, refresh it, and see that your new folder is there.\n", "\n", "In the Terminal Window run:\n", "\n", "```\n", "$ rmdir test\n", "```\n", "Hit refresh in the File Browser again to see that the directory is gone.\n", "\n", "![Terminal](../images/terminal.png)\n", "\n", "Back with the Running Terminals and Kernels Tab open, click the \"X\" in your workspace to close the Terminal window. Notice that the Terminal is still running in the background! Click on the terminal in the Running Terminals and Kernels Tab to reopen it (and hit enter or return to get your prompt back). To truly close it, execute in the Terminal window:\n", "\n", "```\n", "$ exit\n", "```\n", "\n", "OR click the “X” shut down button in the Running Terminals tab.\n", "\n", "Doing so will return you to the Launcher. \n", "\n", "
Info
\n", " The terminal is running on the local host when JupyterLab is launched locally, and remote host when invoked through Jupyter Hub.\n", "Warning
\n", " It is generally considered bad practice to include any output in a “.py” file meant to be imported and used within different Python scripts. Such a file should contain only function and class definitions.\n", "Warning
\n", " Cells can be executed in any order you want. You just have to select the cell and Shift+Enter, and select the cells in any order you want. However, if you share your notebook, there is an implicit expectation to execute the cells in the order in which they are presented in the notebook. Be careful with this! If variables are reused or redefined between cells, reordering them could have unintended consequences!\n", "Danger
\n", " If the cell you to refer to does not have a return value, this will raise an error.\n", "