Collapsable / expandable jupyter cells

(ben.bowles) #1

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.

Lesson 2 discussion
Deep Learning Brasília - Lição 1
(Rachel Thomas) #2

@ben.bowles it’s the ‘collapsible headings’ extension:

(ben.bowles) #3

Thanks so much!

(Jeremy Howard (Admin)) #4

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:

(Maxim Pechyonkin) #5

@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.

(Jose Luis Ricon) #6

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


(Rothrock) #10

@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

Useful jupyter notebook tips & plugins / collapsible sections
(Wole Ogunremi) #12


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