File size: 3,576 Bytes
71c6277 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
Runtools
========
Runtools provide a number of additional functions for working with code cells in the IPython notebook:
Code Cell Execution
-------------------
* Execute a single cell
* Execute from top cell to currently selected cell
* Execute from currently selected cell to bottom cell
* Execute all cells
* Execute all cells, ignore exceptions (requires [ipython/pull/6521](https://github.com/ipython/ipython/pull/6521))
* Execute marked code cells (cells with green gutter area are marked)
* Stop execution (duplicate to standard toolbar button)
When executing marked cells, they are put in a execution list, and
executed in order. The execution list can be modified by unmarking
a cell not yet run. The execution list can be stopped by clicking on
`stop execution`. Execution of the currently running cell can be stopped
by pressing `stop execution` twice.
Code Cell Marking
-----------------
* Mark one or more code cell
Code Cell Display
-----------------
* Hide or show input (i.e. the source code) of marked code cells
* Hide or show output of marked code cells
Description
-----------
The *runtools* extension adds a button to turn on/off a floating toolbar:

This adds Code execution buttons:

Codecells can be marked by clicking on the gutter of a codecell or by clicking on the markers toolbar:

Marked codecells can be locked to read-only mode and moved upd and down:

The input and output areas of marked codecells can be hidden:

A IPython notebook with marked cells looks like this:

Demo
----

Internals
---------
New metadata elements added to each cell:
* `cell.metadata.hide_input` - hide input field of the cell
* `cell.metadata.hide_output` - hide output field of the cell
* `cell.metadata.run_control.marked` - mark a codecell
To export a notebook with hidden input/output fields, the custom template `hide_input_output.tpl` is required.
It should have been installed in the `templates` folder.
You can find the `templates` folder of `jupyter_contrib_nbextensions` from python using
```python
from jupyter_contrib_nbextensions.nbconvert_support import templates_directory
print(templates_directory())
```
The template needs to be in a path where nbconvert can find it. This can be your local path or specified in
`jupyter_nbconvert_config` or `jupyter_notebook_config` as `c.Exporter.extra_template_paths`, see [Jupyter docs](https://jupyter-notebook.readthedocs.io/en/latest/config.html).
For HTML export a template is provided as `nbextensions.tpl` in the `jupyter_contrib_nbextensions` templates directory. Alternatively you can create your own template:
```
{%- extends 'full.tpl' -%}
{% block input_group -%}
{%- if cell.metadata.hide_input -%}
{%- else -%}
{{ super() }}
{%- endif -%}
{% endblock input_group %}
{% block output_group -%}
{%- if cell.metadata.hide_output -%}
{%- else -%}
{{ super() }}
{%- endif -%}
{% endblock output_group %}
```
For LaTeX export a different template is required, which is included as `nbextensions.tplx` in the `jupyter_contrib_nbextensions` templates directory. Alternatively you can create your own template:
```
((- extends 'report.tplx' -))
((* block input_group -))
((- if cell.metadata.hide_input -))
((- else -))
((( super() )))
((- endif -))
(( endblock input_group *))
((* block output_group -))
((- if cell.metadata.hide_output -))
((- else -))
((( super() )))
((- endif -))
(( endblock output_group *))
``` |