##// END OF EJS Templates
Rewrote introduction. Introduced concept of *notebook space* and discussion of why the same word 'notebook' is used both for the notebook space and the corresponding notebook document
David P. Sanders -
Show More
@@ -1,573 +1,568
1 1 .. _htmlnotebook:
2 2
3 3 The IPython Notebook
4 4 ====================
5 5
6 6 .. seealso::
7 7
8 8 :ref:`Installation requirements <installnotebook>` for the Notebook.
9 9
10 10 The IPython Notebook combines two components:
11 11
12 * A web application, called the *IPython Notebook web app*, for interactive
13 authoring of literate computations, in which explanatory text, mathematics,
14 computations and rich media output may be combined. Input and output are stored in persistent cells that may be edited in-place.
12 * **The *IPython Notebook* web application**:
15 13
16 * Plain text documents, called *notebook documents*, or *notebooks*, for recording and distributing the results of the rich computations.
14 The IPython Notebook web app is a browser-based tool for interactive authoring of literate computations, in which explanatory text, mathematics,computations and rich media output may be combined. Input and output are stored in persistent cells that may be edited in-place.
17 15
18 In the documentation, the distinction between the *N*otebook app and *n*otebook documents is made by capitalization.
16 * **Notebook documents**:
19 17
20 The Notebook app automatically saves, at certain intervals, the current state of the computational process occurring in the web browser to the corresponding notebook document.
18 *Notebook documents*, or *notebooks*, are plain text documents which record all inputs and outputs of the computations, interspersed with text, mathematics and HTML 5 representations of objects, in a literate style.
21 19
22 Note that it is also common to refer to the current state of the computation,
23 as represented by the sequence of input cells in the Notebook app, as a
24 *notebook*. There is no problem with confounding these two concepts, since
25 there is actually a one-to-one correspondence between what you see on the
26 screen inside the app, and what is stored in the corresponding ``.ipynb``
27 notebook document.
20 Since the similarity in names can lead to some confusion, in the documentation, we will always use the typographical distinction between the *N*otebook app and *n*otebook documents via the respective capitalization. Here we are thinking of the Notebook app as being a proper noun. We will also always refer to the "Notebook app" when we are referring to the browser-based interface, to increase clarity.
28 21
22 We refer to the current state of the computational process taking place in the Notebook app, i.e. the (numbered) sequence of input and output cells, as the
23 *notebook space*. Notebook documents provide an *exact*, *one-to-one* record of all the content in the notebook space, and the Notebook app automatically saves, at certain intervals, the contents of the notebook space to a notebook document stored on disk, with the same name as the title of the notebook space, and the file extension ".ipynb". For this reason, there is no confusion about using the same name "notebook" for both the notebook space and the corresonding notebook document.
29 24
30 25 Features of the IPython Notebook web app
31 26 ----------------------------------------
32 27
33 28 Some of the main features of the IPython Notebook app include:
34 29
35 30 * In-browser editing, syntax highlighting, tab completion and autoindentation for code.
36 31 * Mix code with rich text using the Markdown markup language.
37 32 * Include mathematical equations using LaTeX notation, rendered directly in the browser by MathJax.
38 33 * Display rich data representations (e.g. HTML / LaTeX / SVG) as the result of computations.
39 34 * Include inline figures rendered by the ``matplotlib`` library with publication quality, in a range of formats (SVG / PDF / PNG).
40 35
41 36 If you have ever used the Mathematica or SAGE notebooks (the latter is also
42 37 web-based__) you should feel right at home. If you have not, you will be
43 38 able to learn how to use the IPython Notebook in just a few minutes.
44 39
45 40 .. __: http://sagenb.org
46 41
47 42
48 43 Notebook documents
49 44 ------------------
50 45
51 46 Notebook document files are just standard text files with the extension
52 47 ``.ipynb``, stored in the working directory on your computer. This file can be easily put under version control and shared with colleagues.
53 48
54 49 Despite the fact that the notebook documents are plain text files, they use
55 50 the JSON format in order to store a *complete*, *reproducible*, *one-to-one* copy of the state of the computational state as it is inside the Notebook app.
56 51 All computations carried out, and the corresponding results obtained, are combined in a literate way, mixing them with descriptive text, mathematics, and HTML 5 representations of objects.
57 52
58 53 Notebooks may easily be exported to a range of static formats, including
59 54 HTML (for example, for blog posts), PDF and slide shows.
60 55 Furthermore, any publicly available notebook may be shared via the
61 56 `IPython Notebook Viewer <http://nbviewer.ipython.org>`_ service, which will
62 57 provide it as a static web page. The results may thus be shared without having to install anything.
63 58
64 59 See :ref:`our installation documentation <install_index>` for directions on
65 60 how to install the notebook and its dependencies.
66 61
67 62 .. note::
68 63
69 64 You can start more than one notebook server at the same time, if you want to
70 65 work on notebooks in different directories. By default the first notebook
71 66 server starts on port 8888, and later notebook servers search for ports near
72 67 that one. You can also manually specify the port with the ``--port``
73 68 option.
74 69
75 70
76 71 Starting up the IPython Notebook web app
77 72 ----------------------------------------
78 73
79 74 The Notebook web app is started with the command::
80 75
81 76 $ ipython notebook
82 77
83 78 The landing page of the notebook server application, the *dashboard*, shows the notebooks currently available in the *working directory* (the directory from which the notebook was started).
84 79 You can create new notebooks from the dashboard with the ``New Notebook``
85 80 button, or open existing ones by clicking on their name.
86 81 You can also drag and drop ``.ipynb`` notebooks and standard ``.py`` Python source code files into the notebook list area.
87 82
88 83 ``.py`` files will be imported into the IPython Notebook as a notebook with the same name, but an ``.ipynb`` extension, located in the working directory. The notebook will consist of a single cell containing all the
89 84 code in the ``.py`` file, which you can later manually partition into individual cells.
90 85
91 86 .. Alternatively, prior to importing the ``.py``, you can manually add ``# <nbformat>2</nbformat>`` at the start of the file, and then add separators for text and code cells, to get a cleaner import with the file already broken into individual cells.
92 87
93 88
94 89 The IPython Notebook web app is based on a server-client structure.
95 90 This server uses a two-process kernel architecture based on ZeroMQ, as well as Tornado for serving HTTP requests. Other clients may connect to the same underlying IPython kernel.
96 91
97 92
98 93 When you open or create a new notebook, your browser tab will reflect the name of that notebook, prefixed with "IPy".
99 94 The URL is currently not meant to be human-readable and is not persistent across invocations of the notebook server; however, this will change in a future version of IPython.
100 95
101 96
102 97 Notebook user interface
103 98 -----------------------
104 99
105 100 When you finally start editing a notebook document in the Notebook, you will be presented with the title of the notebook, a *menu bar*, a *toolbar* and an empty *input cell*.
106 101
107 102 Notebook title
108 103 ~~~~~~~~~~~~~~
109 104 The title of the notebook document that is currently being edited is displayed at the top of the page, next to the ``IP[y]: Notebook`` logo. This title may be edited directly by clicking on it. The title is reflected in the name of the ``.ipynb`` notebook document file that is saved.
110 105
111 106 Menu bar
112 107 ~~~~~~~~
113 108 The menu bar presents different options that may be used to manipulate the way the Notebook functions.
114 109
115 110 Toolbar
116 111 ~~~~~~~
117 112 The tool bar gives handy icons for the most-used operations within the Notebook.
118 113
119 114
120 115 Input cells
121 116 -----------
122 117 Input cells are the core of the functionality of the IPython Notebook.
123 118 They are regions in the document where you can enter different types of text and commands. These regions are then executed using :kbd:`Shift-Enter`, at which point the Notebook executes the current input cell, displays the resulting output beneath it, and adds a new input cell below.
124 119
125 120 The notebook consists of a sequence of input cells,
126 121 providing the means to direct the computational process.
127 122
128 123
129 124 Basic workflow
130 125 --------------
131 126 The normal workflow in a notebook is, then, quite similar to a standard IPython session, with the difference that you can edit cells in-place multiple
132 127 times until you obtain the desired results, rather than having to
133 128 rerun separate scripts with the ``%run`` magic command. (Magic commands do, however, also work in the notebook; see below). Typically, you'll work on a problem in pieces,
134 129 organizing related pieces into cells and moving forward as previous
135 130 parts work correctly. This is much more convenient for interactive exploration than breaking up a computation into scripts that must be
136 131 executed together, especially if parts of them take a long time to run
137 132
138 133 The only significant limitation that the notebook currently has, compared to the Qt console, is that it cannot run any code that
139 134 expects input from the kernel (such as scripts that call
140 135 :func:`raw_input`). Very importantly, this means that the ``%debug``
141 136 magic does *not* currently work in the notebook! This limitation will
142 137 be overcome in the future, but in the meantime, there is a way to debug problems in the notebook: you can attach a Qt console to your existing notebook kernel, and run ``%debug`` from the Qt console.
143 138 If your notebook is running on a local
144 139 computer (i.e. if you are accessing it via your localhost address at ``127.0.0.1``), you can just type ``%qtconsole`` in the notebook and a Qt console will open up, connected to that same kernel.
145 140
146 141 At certain moments, it may be necessary to interrupt a particularly long calculation, or even to kill the entire computational process. This may be achieved by interrupting or restarting the kernel, respectively.
147 142 After a restart, all relevant cells must be re-evaluated
148 143
149 144
150 145 A notebook may be downloaded in either ``.ipynb`` or raw ``.py`` form from the menu option ``File -> Download as``
151 146 Choosing the ``.py`` option removes all output and saves the text cells
152 147 in comment areas. See ref:`below <notebook_format>` for more details on the
153 148 notebook format.
154 149
155 150
156 151 .. warning::
157 152
158 153 While in simple cases you can "roundtrip" a notebook to Python, edit the
159 154 Python file, and then import it back without loss of main content, this is in general *not guaranteed to work*. First, there is extra metadata
160 155 saved in the notebook that may not be saved to the ``.py`` format. And as
161 156 the notebook format evolves in complexity, there will be attributes of the
162 157 notebook that will not survive a roundtrip through the Python form. You
163 158 should think of the Python format as a way to output a script version of a
164 159 notebook and the import capabilities as a way to load existing code to get a
165 160 notebook started. But the Python version is *not* an alternate notebook
166 161 format.
167 162
168 163
169 164 Keyboard shortcuts
170 165 ------------------
171 166 All actions in the notebook can be achieved with the mouse, but we have also
172 167 added keyboard shortcuts for the most common ones, so that productive use of
173 168 the notebook can be achieved with minimal mouse intervention. The main
174 169 key bindings you need to remember are:
175 170
176 171 * :kbd:`Shift-Enter`:
177 172 execute the current cell, show output (if any), and jump
178 173 to the next cell below. If :kbd:`Shift-Enter`
179 174 was invoked on the last input line, a new code cell will also be created. Note that in the notebook, simply using :kbd:`Enter` *never* forces execution, it simply inserts a new line in the current cell. Therefore, in the notebook you must always use :kbd:`Shift-Enter` to get execution (or use the mouse and click on the ``Run Selected`` button).
180 175
181 176 * :kbd:`Alt-Enter`:
182 177 this combination is similar to the previous one, with the
183 178 exception that, if the next cell below is not empty, a new code cell will be
184 179 added to the notebook, even if the cell execution happens not in the last cell. :kbd:`Alt-Enter`: is a shortcut for the sequence :kbd:`Shift-Enter`, :kbd:`Ctrl-m a`.
185 180
186 181 * :kbd:`Ctrl-Enter`:
187 182 execute the current cell in "terminal mode", where any
188 183 output is shown, but the cursor remains in the current cell. This is convenient to do quick in-place experiments, or query things like filesystem content, without creating additional cells that you may not want saved in your notebook.
189 184
190 185 * :kbd:`Ctrl-m`:
191 186 this is the prefix for all other keybindings, which consist of an additional single letter or character. Type :kbd:`Ctrl-m h` (that is, the sole letter
192 187 :kbd:`h` after :kbd:`Ctrl-m`) and IPython will show you the remaining available keybindings.
193 188
194 189
195 190
196 191
197 192
198 193 Cell types
199 194 ----------
200 195 Each IPython input cell has a *cell type*.
201 196 There is a restricted number of possible cell types, which may be set by using the cell type dropdown on the toolbar, or via the following keyboard shortcuts:
202 197
203 198 * **code**: :kbd:`Ctrl-m y`
204 199 * **markdown**: :kbd:`Ctrl-m m`
205 200 * **raw**: :kbd:`Ctrl-m t`
206 201 * **heading**: :kbd:`Ctrl-m 1` - :kbd:`Ctrl-m 6`
207 202
208 203
209 204 Code cells
210 205 ~~~~~~~~~~
211 206 Code cells contain code written in some computer language, which is Python by default. When the cell is executed with :kbd:`Shift-Enter`, this code is executed, and the result returned by Python (or the corresponding language) after running the code will be displayed as its output.
212 207
213 208 Code may be edited inline in the cell, with full syntax highlighting.
214 209
215 210
216 211 Rich text using Markdown
217 212 ~~~~~~~~~~~~~~~~~~~~~~~~
218 213 The computational process may be documented in a literate way using rich text.
219 214 For this purpose, the Notebook provides markdown cells. Text is entered using Markdown_ syntax, allowing for italics, bold, ordered and unordered lists, etc. This is rendered using Markdown syntax to a rich HTML representation when the cell is executed. In this case, the output *replaces* the input cell.
220 215
221 216 Within markdown cells, mathematics can be included in a straightforward manner using LaTeX notation: ``$...$`` for inline math and ``$$...$$`` for displayed math. Standard LaTeX environments, such as ``\begin{equation}...\end{equation}``, also work. New commands may be defined using standard LaTeX commands, placed anywhere in a markdown cell.
222 217
223 218 Raw cells
224 219 ~~~~~~~~~
225 220 Raw cells provide a place to put additional information which is not evaluated by the Notebook. This can be used, for example, for extra information to be used when the notebook is exported to a certain format.
226 221
227 222
228 223 Magic commands
229 224 --------------
230 225 Magic commands, or *magics*, are one-word commands beginning with the symbol ``%``, which send commands to IPython itself (as opposed to standard Python commands which are exported to be run in a Python interpreter).
231 226
232 227 Magics control different elements of the way that the IPython notebook operates. They are entered into standard code cells and executed as usual with :kbd:`Shift-Enter`.
233 228
234 229 There are two types of magics: *line magics*, which begin with a single ``%`` and operate on a single line of the code cell; and *cell magics*, which begin with ``%%`` and operate on the entire contents of the cell.
235 230
236 231 Line magics
237 232 ˜˜˜˜˜˜˜˜˜˜˜
238 233 Some of the available line magics are the following:
239 234
240 235 * ``%load``:
241 236 Loads a file and places its content into a new code cell.
242 237
243 238 * ``%timeit``:
244 239 A simple way to time how long a single line of code takes to run
245 240
246 241 * ``%config``:
247 242 Configuration of the IPython Notebook
248 243
249 244 * ``%lsmagic``:
250 245 Provides a list of all available magic commands
251 246
252 247 Cell magics
253 248 ˜˜˜˜˜˜˜˜˜˜˜
254 249
255 250 * ``%%bash``:
256 251 Send the contents of the code cell to be executed by ``bash``
257 252
258 253 * ``%%file``:
259 254 Writes a file with with contents of the cell. *Caution*: The file is ovewritten without asking.
260 255
261 256 * ``%%R``:
262 257 Execute the contents of the cell using the R language.
263 258
264 259 * ``%%cython``:
265 260 Execute the contents of the cell using ``Cython``.
266 261
267 262
268 263
269 264 Plotting
270 265 --------
271 266 One major feature of the Notebook is the ability to capture the result of plots as inline output. IPython is designed to work seamlessly together with
272 267 the ``%matplotlib`` plotting library. In order to set this up, the
273 268 ``%matplotlib`` magic command must be run before any plotting takes place.
274 269
275 270 Note that ``%matplotlib`` only sets up IPython to work correctly with ``matplotlib``; it does not actually execute any ``import`` commands and does not add anything to the namespace.
276 271
277 272 There is an alternative magic, ``%pylab``, which, in addition, also executes a sequence of standard ``import`` statements required for working with the
278 273 ``%matplotlib`` library. In particular, it automatically imports all names in the ``numpy`` and ``matplotlib`` packages to the namespace. A less invasive solution is ``%pylab --no-import-all``, which imports just the standard names
279 274 ``np`` for the ``numpy`` module and ``plt`` for the ``matplotlib.pyplot`` module.
280 275
281 276 When the default ``%matplotlib`` or ``%pylab`` magics are used, the output of a plotting command is captured in a *separate* window. An alternative is to use::
282 277 ``%matplotlib inline``
283 278 which captures the output inline within the notebook format. This has the benefit that the resulting plots will be stored in the notebook document.
284 279
285 280
286 281 Converting notebooks to other formats
287 282 -------------------------------------
288 283 Newly added in the 1.0 release of IPython is the ``nbconvert`` tool to convert a notebook document into another static format. This is a command line tool; at present, this functionality is not available to export directly from within the Notebook app. The syntax is::
289 284
290 285 $ ipython nbconvert notebook.ipynb
291 286
292 287 for standard HTML output, or::
293 288
294 289 $ ipython nbconvert --format=FORMAT notebook.ipynb
295 290
296 291 where ``FORMAT`` is the desired export format. Options for this format include:
297 292
298 293 * ``full_html``:
299 294 Standard HTML
300 295
301 296 * ``simple_html``:
302 297 A simplified version of HTML
303 298
304 299 * ``reveal``:
305 300 A format to be used with the ``reveal.js`` package for slideshow presentations.
306 301
307 302 * ``sphinx_howto``:
308 303 A standard documentation format.
309 304
310 305 * ``latex``:
311 306 Produces LaTeX output which may be compiled with ``pdflatex`` to PDF.
312 307
313 308
314 309 Configuration
315 310 -------------
316 311 The IPython Notebook can be run with a variety of command line arguments.
317 312 To see a list of available options enter::
318 313
319 314 $ ipython notebook --help
320 315
321 316 Defaults for these options can also be set by creating a file named
322 317 ``ipython_notebook_config.py`` in your IPython *profile folder*. The profile folder is a subfolder of your IPython directory; ``ipython locate`` will show you where it is located.
323 318
324 319 To create a new set of default configuration files, with lots of information on available options, use::
325 320
326 321 $ ipython profile create
327 322
328 323 .. seealso:
329 324
330 325 :ref:`config_overview`, in particular :ref:`Profiles`.
331 326
332 327
333 328 Extracting standard Python files from notebooks
334 329 -----------------------------------------------
335 330
336 331 The native format of the notebook, a file with a ``.ipynb`` `extension, is a
337 332 JSON container of all the input and output of the notebook, and therefore not
338 333 valid Python by itself. This means that by default, you cannot directly
339 334 import a notebook from Python, nor execute it as a normal python script.
340 335
341 336 But if you want to be able to use notebooks also as regular Python files, you can start the notebook server with::
342 337
343 338 ipython notebook --script
344 339
345 340 or you can set this option permanently in your configuration file with::
346 341
347 342 c.NotebookManager.save_script=True
348 343
349 344 This will instruct the notebook server to save the ``.py`` export of each
350 345 notebook, in addition to the ``.ipynb``, at every save. These are standard
351 346 ``.py`` files, and so they can be ``%run``, imported from regular IPython
352 347 sessions or other notebooks, or executed at the command line. Since we export
353 348 the raw code you have typed, for these files to be importable from other code,
354 349 you will have to avoid using syntax such as ``%magic``s and other IPython-specific extensions to the language.
355 350
356 351 In regular practice, the standard way to differentiate importable code from the
357 352 'executable' part of a script is to put at the bottom::
358 353
359 354 if __name__ == '__main__':
360 355 # rest of the code...
361 356
362 357 Since all cells in the notebook are run as top-level code, you will need to
363 358 similarly protect *all* cells that you do not want executed when other scripts
364 359 try to import your notebook. A convenient shortand for this is to define early
365 360 on::
366 361
367 362 script = __name__ == '__main__'
368 363
369 364 and then on any cell that you need to protect, use::
370 365
371 366 if script:
372 367 # rest of the cell...
373 368
374 369
375 370 .. _notebook_security:
376 371
377 372 Security
378 373 --------
379 374
380 375 You can protect your Notebook server with a simple singlepassword by
381 376 setting the :attr:`NotebookApp.password` configurable. You can prepare a
382 377 hashed password using the function :func:`IPython.lib.security.passwd`:
383 378
384 379 .. sourcecode:: ipython
385 380
386 381 In [1]: from IPython.lib import passwd
387 382 In [2]: passwd()
388 383 Enter password:
389 384 Verify password:
390 385 Out[2]: 'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'
391 386
392 387 .. note::
393 388
394 389 :func:`~IPython.lib.security.passwd` can also take the password as a string
395 390 argument. **Do not** pass it as an argument inside an IPython session, as it
396 391 will be saved in your input history.
397 392
398 393 You can then add this to your :file:`ipython_notebook_config.py`, e.g.::
399 394
400 395 # Password to use for web authentication
401 396 c.NotebookApp.password = u'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'
402 397
403 398 When using a password, it is a good idea to also use SSL, so that your password
404 399 is not sent unencrypted by your browser. You can start the notebook to
405 400 communicate via a secure protocol mode using a self-signed certificate with the command::
406 401
407 402 $ ipython notebook --certfile=mycert.pem
408 403
409 404 .. note::
410 405
411 406 A self-signed certificate can be generated with ``openssl``. For example, the following command will create a certificate valid for 365 days with both the key and certificate data written to the same file::
412 407
413 408 $ openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem
414 409
415 410 Your browser will warn you of a dangerous certificate because it is
416 411 self-signed. If you want to have a fully compliant certificate that will not
417 412 raise warnings, it is possible (but rather involved) to obtain one for free,
418 413 `as explained in detailed in this tutorial`__.
419 414
420 415 .. __: http://arstechnica.com/security/news/2009/12/how-to-get-set-with-a-secure-sertificate-for-free.ars
421 416
422 417 Keep in mind that when you enable SSL support, you'll need to access the
423 418 notebook server over ``https://``, not over plain ``http://``. The startup
424 419 message from the server prints this, but it's easy to overlook and think the
425 420 server is for some reason non-responsive.
426 421
427 422
428 423 Connecting to an existing kernel
429 424 ---------------------------------
430 425
431 426 The notebook server always prints to the terminal the full details of
432 427 how to connect to each kernel, with lines like::
433 428
434 429 [IPKernelApp] To connect another client to this kernel, use:
435 430 [IPKernelApp] --existing kernel-3bb93edd-6b5a-455c-99c8-3b658f45dde5.json
436 431
437 432 This is the name of a JSON file that contains all the port and
438 433 validation information necessary to connect to the kernel. You can
439 434 manually start a Qt console with::
440 435
441 436 ipython qtconsole --existing kernel-3bb93edd-6b5a-455c-99c8-3b658f45dde5.json
442 437
443 438 and if you only have a single kernel running, simply typing::
444 439
445 440 ipython qtconsole --existing
446 441
447 442 will automatically find it (it will always find the most recently
448 443 started kernel if there is more than one). You can also request this
449 444 connection data by typing ``%connect_info``; this will print the same
450 445 file information as well as the content of the JSON data structure it contains.
451 446
452 447
453 448 Running a public notebook server
454 449 --------------------------------
455 450
456 451 If you want to access your notebook server remotely with just a web browser,
457 452 here is a quick set of instructions. Start by creating a certificate file and
458 453 a hashed password as explained above. Then, create a custom profile for the
459 454 notebook. At the command line, type::
460 455
461 456 ipython profile create nbserver
462 457
463 458 In the profile directory, edit the file ``ipython_notebook_config.py``. By
464 459 default the file has all fields commented, the minimum set you need to
465 460 uncomment and edit is here::
466 461
467 462 c = get_config()
468 463
469 464 # Kernel config
470 465 c.IPKernelApp.pylab = 'inline' # if you want plotting support always
471 466
472 467 # Notebook config
473 468 c.NotebookApp.certfile = u'/absolute/path/to/your/certificate/mycert.pem'
474 469 c.NotebookApp.ip = '*'
475 470 c.NotebookApp.open_browser = False
476 471 c.NotebookApp.password = u'sha1:bcd259ccf...your hashed password here'
477 472 # It's a good idea to put it on a known, fixed port
478 473 c.NotebookApp.port = 9999
479 474
480 475 You can then start the notebook and access it later by pointing your browser to
481 476 ``https://your.host.com:9999`` with ``ipython notebook --profile=nbserver``.
482 477
483 478 Running with a different URL prefix
484 479 -----------------------------------
485 480
486 481 The notebook dashboard (i.e. the default landing page with an overview
487 482 of all your notebooks) typically lives at a URL path of
488 483 "http://localhost:8888/". If you want to have it, and the rest of the
489 484 notebook, live under a sub-directory,
490 485 e.g. "http://localhost:8888/ipython/", you can do so with
491 486 configuration options like these (see above for instructions about
492 487 modifying ``ipython_notebook_config.py``)::
493 488
494 489 c.NotebookApp.base_project_url = '/ipython/'
495 490 c.NotebookApp.base_kernel_url = '/ipython/'
496 491 c.NotebookApp.webapp_settings = {'static_url_prefix':'/ipython/static/'}
497 492
498 493 Using a different notebook store
499 494 --------------------------------
500 495
501 496 By default the notebook server stores notebooks as files in the working
502 497 directory of the notebook server, also known as the ``notebook_dir``. This
503 498 logic is implemented in the :class:`FileNotebookManager` class. However, the
504 499 server can be configured to use a different notebook manager class, which can
505 500 store the notebooks in a different format. Currently, we ship a
506 501 :class:`AzureNotebookManager` class that stores notebooks in Azure blob
507 502 storage. This can be used by adding the following lines to your
508 503 ``ipython_notebook_config.py`` file::
509 504
510 505 c.NotebookApp.notebook_manager_class = 'IPython.html.services.notebooks.azurenbmanager.AzureNotebookManager'
511 506 c.AzureNotebookManager.account_name = u'paste_your_account_name_here'
512 507 c.AzureNotebookManager.account_key = u'paste_your_account_key_here'
513 508 c.AzureNotebookManager.container = u'notebooks'
514 509
515 510 In addition to providing your Azure Blob Storage account name and key, you will
516 511 have to provide a container name; you can use multiple containers to organize
517 512 your Notebooks.
518 513
519 514 .. _notebook_format:
520 515
521 516 Notebook JSON format
522 517 ====================
523 518
524 519 Notebooks are JSON files with an ``.ipynb`` extension, formatted
525 520 as legibly as possible with minimal extra indentation and cell content broken
526 521 across lines to make them reasonably friendly to use in version-control
527 522 workflows. You should be very careful if you ever manually edit this JSON
528 523 data, as it is extremely easy to corrupt its internal structure and make the
529 524 file impossible to load. In general, you should consider the notebook as a
530 525 file meant only to be edited by the IPython Notebook app itself, not for hand-editing.
531 526
532 527 .. note::
533 528
534 529 Binary data such as figures are directly saved in the JSON file. This
535 530 provides convenient single-file portability, but means that the files can
536 531 be large; ``diff``s of binary data also are not very meaningful. Since the
537 532 binary blobs are encoded in a single line, they affect only one line of
538 533 the ``diff`` output, but they are typically very long lines. You can use the ``Cell -> All Output -> Clear`` menu option to remove all output from a notebook prior to committing it to version control, if this is a concern.
539 534
540 535 The notebook server can also generate a pure Python version of your notebook,
541 536 using the ``File -> Download as`` menu option. The resulting ``.py`` file will
542 537 contain all the code cells from your notebook verbatim, and all text cells
543 538 prepended with a comment marker. The separation between code and text
544 539 cells is indicated with special comments and there is a header indicating the
545 540 format version. All output is stripped out when exporting to Python.
546 541
547 542 Here is an example of the Python output from a simple notebook with one text cell and one code input cell::
548 543
549 544 # <nbformat>2</nbformat>
550 545
551 546 # <markdowncell>
552 547
553 548 # A text cell
554 549
555 550 # <codecell>
556 551
557 552 print "Hello, IPython!"
558 553
559 554
560 555 Known issues
561 556 ============
562 557
563 558 When behind a proxy, especially if your system or browser is set to autodetect
564 559 the proxy, the Notebook app might fail to connect to the server's websockets,
565 560 and present you with a warning at startup. In this case, you need to configure
566 561 your system not to use the proxy for the server's address.
567 562
568 563 In Firefox, for example, go to the Preferences panel, Advanced section,
569 564 Network tab, click 'Settings...', and add the address of the notebook server
570 565 to the 'No proxy for' field.
571 566
572 567
573 568 .. _Markdown: http://daringfireball.net/projects/markdown/basics
General Comments 0
You need to be logged in to leave comments. Login now