Hiding code cell on launch

Hello everyone,

Is there a way to have all code cells hidden when a notebook is launched/opened? I’m just looking for the same functionality you get when you click on the bar on the left that “collapses” a code cell.

It would be even better if this could be determined by tags set on the cells, similar to what jupyter-book does.


Hi @geirfreysson,
Currently, if you save the notebook after using View > Collapse All Code, it reopens with that same code collapsed. I just tested it in JupyterLab >= 1.0 launched from here and here by collapsing it in one session, saving the notebook and opening in another session. It should work for individual cells if you want that, too.
You can view the state in the meta data by right-clicking on the notebooks in the JupyterLab file browser and opening the notebooks with Open with > Editor and seeing "source_hidden": true for cells.

Or are you asking if you can enforce this for notebooks where this wasn’t previously set?
That probably can be done by reading in a notebook with nbformat and designating the output be adjusted to have that attribute by combining the process outlined here to open a notebook and step through cells with details here to adjust the meta-data in the output.

Hi @fomightez. That’s super helpful. I tested it as well and it works perfectly.

I wonder if it’s a 1.0 thing and I just didn’t noticed this functionality had been added - or maybe I just wasn’t paying attention at all!

Many thanks for your help! Problem solved!

1 Like

I think it may have been put in last year according to here and here.
I am finding the 1.0 milestone definitely allowed a lot of things that had been in flux to be sorted and some rough edges polished nicely. I think I am going to make sure I specify it in all my Binderized repos for the near future.

Just to confirm: yes, it’s something added in 1.0. (I implemented the final version of it in https://github.com/jupyterlab/jupyterlab/pull/5968 :).

1 Like

Thanks, @jasongrout
Oops. Yes, I was getting confused with the output persistence shoring up threads and changelogs.

Well done, it’s crucial for how we’re want to use Jupyter. And thanks for confirming, I was feeling a bit silly asking if it was there the whole time!

1 Like

Thanks for vindicating the days spent on designing and implementing this (and not just by me) :).