##// END OF EJS Templates
Merge pull request #8778 from SylvainCorlay/Meta...
Merge pull request #8778 from SylvainCorlay/Meta Use isinstance to check for types

File last commit:

r20540:0e53a88c
r21631:3ac9be53 merge
Show More
Notebook Basics.ipynb
313 lines | 11.6 KiB | text/plain | TextLexer
/ examples / Notebook / Notebook Basics.ipynb
Brian E. Granger
Adding basic examples notebook about modal editing.
r14097 {
Min RK
upate exmaple notebooks to nbformat v4
r18669 "cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Notebook Basics"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
Jonathan Frederic
A LOT OF CLEANUP IN examples/Notebook
r20536 "## Running the Notebook Server"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The IPython notebook server is a custom web server that runs the notebook web application. Most of the time, users run the notebook server on their local computer using IPython's command line interface."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Starting the notebook server using the command line"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can start the notebook server from the command line (Terminal on Mac/Linux, CMD prompt on Windows) by running the following command: \n",
Min RK
upate exmaple notebooks to nbformat v4
r18669 "\n",
" ipython notebook\n",
"\n",
Jonathan Frederic
A LOT OF CLEANUP IN examples/Notebook
r20536 "This will print some information about the notebook server in your terminal, including the URL of the web application (by default, `http://127.0.0.1:8888`). It will then open your default web browser to this URL.\n",
"\n",
Jonathan Frederic
@Carreau 's review comments.
r20539 "When the notebook opens, you will see the **notebook dashboard**, which will show a list of the notebooks, files, and subdirectories in the directory where the notebook server was started (as seen in the next section, below). Most of the time, you will want to start a notebook server in the highest directory in your filesystem where notebooks can be found. Often this will be your home directory."
Min RK
upate exmaple notebooks to nbformat v4
r18669 ]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
Jonathan Frederic
A LOT OF CLEANUP IN examples/Notebook
r20536 "### Additional options"
Min RK
upate exmaple notebooks to nbformat v4
r18669 ]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
Jonathan Frederic
More cleaner is more better
r20540 "By default, the notebook server starts on port 8888. If port 8888 is unavailable, the notebook server searchs the next available port.\n",
Min RK
upate exmaple notebooks to nbformat v4
r18669 "\n",
Jonathan Frederic
A LOT OF CLEANUP IN examples/Notebook
r20536 "You can also specify the port manually:\n",
Min RK
upate exmaple notebooks to nbformat v4
r18669 "\n",
Jonathan Frederic
A LOT OF CLEANUP IN examples/Notebook
r20536 " ipython notebook --port 9999\n",
Min RK
upate exmaple notebooks to nbformat v4
r18669 "\n",
Jonathan Frederic
A LOT OF CLEANUP IN examples/Notebook
r20536 "Or start notebook server without opening a web browser.\n",
Min RK
upate exmaple notebooks to nbformat v4
r18669 "\n",
Jonathan Frederic
A LOT OF CLEANUP IN examples/Notebook
r20536 " ipython notebook --no-browser\n",
Min RK
upate exmaple notebooks to nbformat v4
r18669 "\n",
Jonathan Frederic
A LOT OF CLEANUP IN examples/Notebook
r20536 "The notebook server has a number of other command line arguments that can be displayed with the `--help` flag: \n",
Min RK
upate exmaple notebooks to nbformat v4
r18669 "\n",
Jonathan Frederic
A LOT OF CLEANUP IN examples/Notebook
r20536 " ipython notebook --help"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## The Notebook dashboard"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"When you first start the notebook server, your browser will open to the notebook dashboard. The dashboard serves as a home page for the notebook. Its main purpose is to display the notebooks and files in the current directory. For example, here is a screenshot of the dashboard page for the `examples` directory in the IPython repository:\n",
"\n",
"<img src=\"images/dashboard_files_tab.png\" width=\"791px\"/>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The top of the notebook list displays clickable breadcrumbs of the current directory. By clicking on these breadcrumbs or on sub-directories in the notebook list, you can navigate your file system.\n",
Min RK
upate exmaple notebooks to nbformat v4
r18669 "\n",
Jonathan Frederic
A LOT OF CLEANUP IN examples/Notebook
r20536 "To create a new notebook, click on the \"New\" button at the top of the list and select a kernel from the dropdown (as seen below). Which kernels are listed depend on what's installed on the server. Some of the kernels in the screenshot below may not exist as an option to you.\n",
Min RK
upate exmaple notebooks to nbformat v4
r18669 "\n",
Jonathan Frederic
A LOT OF CLEANUP IN examples/Notebook
r20536 "<img src=\"images/dashboard_files_tab_new.png\" width=\"202px\" />"
Min RK
upate exmaple notebooks to nbformat v4
r18669 ]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
Jonathan Frederic
A LOT OF CLEANUP IN examples/Notebook
r20536 "Notebooks and files can be uploaded to the current directory by dragging a notebook file onto the notebook list or by the \"click here\" text above the list.\n",
"\n",
"The notebook list shows green \"Running\" text and a green notebook icon next to running notebooks (as seen below). Notebooks remain running until you explicitly shut them down; closing the notebook's page is not sufficient.\n",
"\n",
"<img src=\"images/dashboard_files_tab_run.png\" width=\"777px\"/>"
Min RK
upate exmaple notebooks to nbformat v4
r18669 ]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
Jonathan Frederic
A LOT OF CLEANUP IN examples/Notebook
r20536 "To shutdown, delete, duplicate, or rename a notebook check the checkbox next to it and an array of controls will appear at the top of the notebook list (as seen below). You can also use the same operations on directories and files when applicable.\n",
"\n",
"<img src=\"images/dashboard_files_tab_btns.png\" width=\"301px\" />"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To see all of your running notebooks along with their directories, click on the \"Running\" tab:\n",
"\n",
"<img src=\"images/dashboard_running_tab.png\" width=\"786px\" />\n",
"\n",
"This view provides a convenient way to track notebooks that you start as you navigate the file system in a long running notebook server."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Overview of the Notebook UI"
Min RK
upate exmaple notebooks to nbformat v4
r18669 ]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If you create a new notebook or open an existing one, you will be taken to the notebook user interface (UI). This UI allows you to run code and author notebook documents interactively. The notebook UI has the following main areas:\n",
"\n",
"* Menu\n",
"* Toolbar\n",
"* Notebook area and cells\n",
"\n",
Jonathan Frederic
A LOT OF CLEANUP IN examples/Notebook
r20536 "The notebook has an interactive tour of these elements that can be started in the \"Help:User Interface Tour\" menu item."
Min RK
upate exmaple notebooks to nbformat v4
r18669 ]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Modal editor"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Starting with IPython 2.0, the IPython Notebook has a modal user interface. This 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 border and a prompt showing in the editor area:\n",
"\n",
"<img src=\"images/edit_mode.png\">\n",
"\n",
"When a cell is in edit mode, you can type into the cell, like a normal text editor."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<div class=\"alert alert-success\">\n",
"Enter edit mode by pressing `Enter` or using the mouse to click on a cell's editor area.\n",
"</div>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Command mode"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Command mode is indicated by a grey cell border:\n",
"\n",
"<img src=\"images/command_mode.png\">\n",
"\n",
"When you are in command mode, you are able to edit the notebook as a whole, but not type into individual cells. Most importantly, in command mode, the keyboard is mapped to a set of shortcuts that let you perform notebook and cell actions efficiently. 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": [
"<div class=\"alert alert-error\">\n",
"Don't try to type into a cell in command mode; unexpected things will happen!\n",
"</div>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<div class=\"alert alert-success\">\n",
"Enter command mode by pressing `Esc` or using the mouse to click *outside* a cell's editor area.\n",
"</div>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Mouse navigation"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"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",
Jonathan Frederic
A LOT OF CLEANUP IN examples/Notebook
r20536 "<img src=\"images/menubar_toolbar.png\" width=\"786px\" />"
Min RK
upate exmaple notebooks to nbformat v4
r18669 ]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The first idea of mouse based navigation is that **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",
"If you are running this notebook in a live session (not on http://nbviewer.ipython.org) try selecting different cells and going between edit and command mode. Try typing into a cell."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The second idea of mouse based navigation is that **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 class='btn btn-default btn-xs'><i class=\"fa fa-play icon-play\"></i></button> button in the toolbar or the \"Cell:Run\" menu item. Similarly, to copy a cell you would select it and click the <button class='btn btn-default btn-xs'><i class=\"fa fa-copy icon-copy\"></i></button> 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.\n",
"\n",
"Markdown and heading cells have one other state that can be modified with the mouse. These cells can either be rendered or unrendered. When they are rendered, you will see a nice formatted representation of the cell's contents. When they are unrendered, you will see the raw text source of the cell. To render the selected cell with the mouse, click the <button class='btn btn-default btn-xs'><i class=\"fa fa-play icon-play\"></i></button> button in the toolbar or the \"Cell:Run\" menu item. To unrender the selected cell, double click on the cell."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Keyboard Navigation"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The modal user interface of the IPython 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",
Jonathan Frederic
A LOT OF CLEANUP IN examples/Notebook
r20536 "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."
Min RK
upate exmaple notebooks to nbformat v4
r18669 ]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We recommend learning the command mode shortcuts 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. Cell types: `y`, `m`, `1-6`, `t`\n",
Thomas Kluyver
Remove mention of Ctrl-J & Ctrl-K shortcuts from example notebook
r20457 "3. Cell creation: `a`, `b`\n",
Min RK
upate exmaple notebooks to nbformat v4
r18669 "4. Cell editing: `x`, `c`, `v`, `d`, `z`, `shift+=`\n",
"5. Kernel operations: `i`, `.`"
]
}
],
Brian E. Granger
Adding basic examples notebook about modal editing.
r14097 "metadata": {
Matthias Bussonnier
Fix font-awesome icons in examples notebook...
r17913 "kernelspec": {
Min RK
add kernel metadata to example notebooks
r20278 "display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
Matthias Bussonnier
Fix font-awesome icons in examples notebook...
r17913 "codemirror_mode": {
"name": "ipython",
"version": 3
},
Min RK
add kernel metadata to example notebooks
r20278 "file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
Jonathan Frederic
A LOT OF CLEANUP IN examples/Notebook
r20536 "version": "3.4.3"
Min RK
add kernel metadata to example notebooks
r20278 }
Brian E. Granger
Adding basic examples notebook about modal editing.
r14097 },
Min RK
upate exmaple notebooks to nbformat v4
r18669 "nbformat": 4,
"nbformat_minor": 0
Min RK
add kernel metadata to example notebooks
r20278 }