NathaneilCapital
NathaneilCapital

Reputation: 1469

Is there a way to convient fold/unfold an ipython cell?

Now ipython notebook could easily hide the output part of a cell by double clicking the left margin of the output. But I havn't figure out a way to hide the whole cell content.

Upvotes: 51

Views: 29454

Answers (7)

ntg
ntg

Reputation: 14075

Yes! :) There now is one! :)

jupyter notebook extensions is a collection of extensions including, but not limited to:

  • code folding
  • Collapsible Headings
  • and many, many more...

The second one can be used to collapse jupyter notebooks on the headers, thus hiding entire sections of cells at once. I just found this and am currently (and probably for the next hour or so) thinking that this is the coolest invention, after sliced bread.

You can even install the whole bunch with a single anaconda command,

conda install -c conda-forge jupyter_nbextensions_configurator

This installs the extensions configurator which integrates them to jupyter and allows you to enable/disable them at will with a click.

Also, the following function should be available in the latest jupyter: triple clicking completely hides output The same happens if you press 'o' in the command mode: it hides the output of the cell in focus.

The jupyter I tried this on was: enter image description here

Upvotes: 0

Linas
Linas

Reputation: 782

If you are running juptyter, then this is relevant: collapse cell in jupyter notebook

In my case, I like the hide_cost extension. Install as

pip3 install hide_code

Visit https://github.com/kirbs-/hide_code/ for more info about this extension.

Upvotes: 3

Jeff Ellen
Jeff Ellen

Reputation: 550

I spent a long time trying to get the codefolding extension to work with my setup, but I couldn't get it to work, even after trying many things including this stackoverflow suggestion. And I probably would have preferred that. However, I did find this page which talks about hiding code cells:

http://blog.nextgenetics.net/?e=99

I ended up putting this snippet in my custom.js and it worked perfectly:

http://pastebin.com/H77xP2vN

Now under my 'View' menu, I have a 3rd option to 'toggle code cells'. It toggles to hide/show only the input, while always showing the output, which is what I'm looking for. State of toggle is not preserved across saving/reopening file as it would have been with codefolding

Upvotes: 1

Torsten Riedling
Torsten Riedling

Reputation: 11

I installed runtools and it works for me. You can fold one or all marked input cells.

https://github.com/ipython-contrib/IPython-notebook-extensions/tree/master/usability/runtools

Upvotes: 1

Dyno Fu
Dyno Fu

Reputation: 9044

hide_input_all extension will hide all input cell. and hide_input will hide the code cell that currently has the focus. my testing shows that all you need to do is loading the hide_input extension.

IPython.load_extensions('usability/hide_input/main');

Upvotes: 2

kriztean
kriztean

Reputation: 329

I did that with jquery.

  1. You need to "print preview" your notebook.
  2. from the browser console: jQuery(".input").hide()

Upvotes: 2

Moses Xu
Moses Xu

Reputation: 2160

Not sure if this is still relevant but the following code folding extension may help:

https://github.com/ipython-contrib/IPython-notebook-extensions/wiki/Codefolding

Upvotes: 6

Related Questions