{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "(This is simplified documentation from https://jupyter-notebook.readthedocs.io. You are more than welcome to visit the aforementioned page for more details)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# What is the Jupyter Notebook?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Introduction" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The Jupyter Notebook is an **interactive computing environment** that enables users to author notebook documents that include: \n", "- Live code\n", "- Interactive widgets\n", "- Plots\n", "- Narrative text\n", "- Equations\n", "- Images\n", "- Video" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "### Components" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The Jupyter Notebook combines three components:\n", "\n", "* **The notebook web application**: An interactive web application for writing and running code interactively and authoring notebook documents.\n", "* **Kernels**: Separate processes started by the notebook web application that runs users' code in a given language and returns output back to the notebook web application. The kernel also handles things like computations for interactive widgets, tab completion and introspection. \n", "* **Notebook documents**: Self-contained documents that contain a representation of all content visible in the notebook web application, including inputs and outputs of the computations, narrative\n", "text, equations, images, and rich media representations of objects. Each notebook document has its own kernel." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Notebook documents" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "When you run the notebook web application on your computer, notebook documents are just **files on your local filesystem with a** `.ipynb` **extension**. This allows you to use familiar workflows for organizing your notebooks into folders and sharing them with others." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Notebooks consist of a **linear sequence of cells**. There are three basic cell types:\n", "\n", "* **Code cells:** Input and output of live code that is run in the kernel\n", "* **Markdown cells:** Narrative text with embedded LaTeX equations\n", "* **Raw cells:** Unformatted text that is included, without modification, when notebooks are converted to different formats using nbconvert" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Notebook Basics" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Modal editor\n", "\n", "Jupyter Notebooks have a modal user interface, which means that the keyboard does different things depending on which mode the Notebook is in. There are two modes: edit mode and command mode." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Edit mode" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Edit mode is indicated by a green cell borderand a prompt showing in the editor area. When a cell is in edit mode, you can type into the cell, like a normal text editor." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "Enter edit mode by pressing `Enter` or using the mouse to click on a cell's editor area.\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Command mode" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Command mode is indicated by a grey cell border with a blue left margin. When you are in command mode, you are able to edit the notebook as a whole, but not type into individual cells. \n", "\n", "Most importantly, in command mode, the keyboard is mapped to a set of shortcuts that let you perform notebook and cell actions efficiently. \n", "\n", "For example, if you are in command mode and you press `c`, you will copy the current cell - no modifier is needed." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "Don't try to type into a cell in command mode; unexpected things will happen!\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "Enter command mode by pressing `Esc` or using the mouse to click *outside* a cell's editor area.\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Mouse navigation\n", "\n", "All navigation and actions in the Notebook are available using the mouse through the menubar and toolbar, which are both above the main Notebook area.\n", "\n", "A couple of basic ideas:\n", "\n", "\n", "- **cells can be selected by clicking on them.** The currently selected cell gets a grey or green border depending on whether the notebook is in edit or command mode. If you click inside a cell's editor area, you will enter edit mode. If you click on the prompt or output area of a cell you will enter command mode.\n", "\n", "- **cell actions usually apply to the currently selected cell**. Thus if you want to run the code in a cell, you would select it and click the button in the toolbar or the \"Cell:Run\" menu item. Similarly, to copy a cell you would select it and click the button in the toolbar or the \"Edit:Copy\" menu item. With this simple pattern, you should be able to do most everything you need with the mouse." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Keyboard Navigation\n", "\n", "The modal user interface of the Jupyter Notebook has been optimized for efficient keyboard usage. This is made possible by having two different sets of keyboard shortcuts: one set that is active in edit mode and another in command mode.\n", "\n", "The most important keyboard shortcuts are `Enter`, which enters edit mode, and `Esc`, which enters command mode.\n", "\n", "In edit mode, most of the keyboard is dedicated to typing into the cell's editor. Thus, in edit mode there are relatively few shortcuts. In command mode, the entire keyboard is available for shortcuts, so there are many more. The `Help`->`Keyboard Shortcuts` dialog lists the available shortcuts." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "I recommend learning the **command mode** shortcuts - you will need to be sure having pressed `Esc` for this - in the following rough order:\n", "\n", "1. Basic navigation: `enter`, `shift-enter`, `up/k`, `down/j`\n", "2. Saving the notebook: `s`\n", "2. Change Cell types: `y`, `m`, `1-6`, `t`\n", "3. Cell creation: `a`, `b`\n", "4. Cell editing: `x`, `c`, `v`, `d`, `z`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Running Code (edit mode)\n", "\n", "* `Shift-Enter` or pressing the button in the toolbar above runs a code cell.\n", "\n", "* `Alt-Enter` runs the current cell and inserts a new one below.\n", "* `Ctrl-Enter` run the current cell and enters command mode." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
Practice: Create a cell below or above using either the keyworad with one of the shortcuts shown before, or using the menu with the mouse. Then, change to edit mode in the created cell and try introducing a number and running the cell using any of the above combinations. Do the same now, but changing the cell to markdown and typing some text in it.
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Cell menu" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The \"Cell\" menu has a number of menu items for running code in different ways. These includes:\n", "\n", "* Run and Select Below\n", "* Run and Insert Below\n", "* Run All\n", "* Run All Above\n", "* Run All Below" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Restarting the kernels" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The kernel maintains the state of a notebook's computations. You can reset this state by restarting the kernel. This is done by clicking on the in the toolbar above." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# MORE RESOURCES" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* Thorugh documentation: https://jupyter-notebook.readthedocs.io. I recommend checking the section dedicated to markdowns. \n", "* jupyter notebooks cheat sheet: https://www.edureka.co/blog/wp-content/uploads/2018/10/Jupyter_Notebook_CheatSheet_Edureka.pdf" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "R", "language": "R", "name": "ir" }, "language_info": { "codemirror_mode": "r", "file_extension": ".r", "mimetype": "text/x-r-source", "name": "R", "pygments_lexer": "r", "version": "3.6.1" } }, "nbformat": 4, "nbformat_minor": 1 }