Collapsable / expandable jupyter cells

Forgive me for asking a non-deep learning related question, but how can I make my jupyter notebooks have collapsable and expandable cells, with little pointers at the side, like @jeremy has it? Such a beautiful way to organize notebooks, unfortunately after quite a few Google search’s the answer doesn’t seem obvious to me.

22 Likes

@ben.bowles it’s the ‘collapsible headings’ extension:
https://github.com/ipython-contrib/jupyter_contrib_nbextensions

32 Likes

Thanks so much!

I’m glad you asked - these little practical tips are just the kinds of things I’m hoping people will take away from this course :slight_smile:

18 Likes

@jeremy In addition to collapsable cells, I also noticed that you seem to be using a custom .css for your Jupyter notebook. I went on to search for different custom Jupyter style sheets but could not find one as beautiful as yours. Would you be so kind as the custom.css that you are using.

3 Likes

It seems to be the grid3 theme from jupyter-themes

I really liked the width of Jeremy’s notebook and found that it is easy to change it in the .container .

grid3 default is much smaller I thought.

renjith@dlp20db:~$ vi ~/.jupyter/custom/custom.css

If you already have custom.css add to the exsisting .container. If You dont have then just create a new file with below contents.

.container {
width:100% !important;
margin-right: auto;
margin-left: auto;
}

I find it very useful to use my entire screen for the notebook.

I have a question regarding reproducibility, say I use these in my notebooks how would that effect someone down the line using my published notebook if they don’t have these extensions installed. Perhaps a warning at the start of the NB with a link to installation and configuration and a code line to install the package. There is a conda package at condo-forge.

Whats cool about expand/collapse is that it implements top down right!!

Hi @renjithmadhavan
Have you any suggestions for taking this a step further. That is given that in anaconda you can set up environments i.e. one for tensorflow and python 2 another for theano and say python 3. How would you keep different appearances for each notebook based on the environment.

Thanks if you have the time to answer but no sweat if you don’t

regards

@RogerS49 For people who don’t have it installed, the styling degrades gracefully. If the CSS/Javascript isn’t there then you just get a markdown cell that is a heading. At least for the collapsible headings. There are several other extensions in there that I don’t know what they do.

I struggled a bit to find instructions to install it. These are the commands that worked for me in the end:

conda install -c conda-forge jupyter_contrib_nbextensions 
cd ~/anaconda3/envs/fastai/lib/python3.6/site-packages/jupyter_contrib_nbextensions/nbextensions
jupyter nbextension install collapsible_headings --user
6 Likes

Awesome!

I also installed the nbextensions configurator, lots of exciting new possibilities!

Cheers

I’d like to add that it is possible to RUN a whole section easily.

I try to separate the code

image

So when I need to run just a part I do:

  1. Enter on the Section you want to select completely
  2. Press Shift + Right
  3. Click Run

More shortcuts on https://jupyter-contrib-nbextensions.readthedocs.io/en/latest/nbextensions/collapsible_headings/readme.html

2 Likes