Collapse or folding code cell in Jupyter notebook

Hi,

I know there is a collapse or folding function when I work in normal editor with .py in Pycharm.

However, it seems this function is not available in Jupyter notebook in Pycharm.

Is there any way that I can fold or collapse code in Jupyter notebook?

4
9 comments

Hi,

Yes, you can fold/unfold regions of your code in Jupyter cells the same way as it works in .py files. If you're talking about folding an entire cell, there's no feature for that, but you can use "fold selection" functionality to select and fold code in the cell.

If you mean some specific folding that doesn't work, please provide more information.

1

I can't find that in Pycharm's notebooks (jupyter) either. The only collapsable things sem to be functions, string literals and maybe something more but you can't decide what should be collapsable and the predetermined ones are inside a code cell. I'd like to collapse an entire section behind a tittle (an h1 or any level markdown tittle); that is much more useful in notebooks. 

I can do that in Collab at least, and I think it could be done at some point in Jupyter notebooks. I went to Collab just because of that though. I do see convenient to use notebooks inside Pycharm, but this is a big productivity deal... 

Any way you (Jetbrains) implement that anytime soon? 

Best!

1

Maybe if the outline (Structure panel) could directly move items, like Collab does, it wouldnt be super  necessary the previous collapse - although it'd still help to just visualize the important things in a glance 

0

any update on the collapsible feature?

1

The headers in Markdown cells can be collapsed and are visible in project structure. In code cells, you can create custom fold regions -- https://www.jetbrains.com/help/pycharm/working-with-source-code.html#expand-or-collapse-code-elements

If that's not what you mean, could you please provide more specifics?

1

Hi, old thread but hoping for a reply.

I've been looking for a solution to collapsible headings in PyCharm Notebooks.

Unlike being able to only fold code within one cell, it would provide the option to fold/hide multiple code-cells and their output.

An example would be the Collapsible-headings extension for Jupyter Notebook.

and after collapsing/folding:

Extension link: https://jupyter-contrib-nbextensions.readthedocs.io/en/latest/nbextensions/collapsible_headings/readme.html

 

This would make it a lot easier to work in PyCharm Notebooks as they grow past 20-40 cells.

3

+1 also looking for this functionality in the jupyter notebook. need to do a lot of scrolling right now to move between cells with lots of code

1

+1 on this markdown heading fold/unfold feature. It would be really helpful to have this. 

1

There is a related feature request PY-65441 on that, please vote for it and feel free to comment. See https://intellij-support.jetbrains.com/hc/en-us/articles/207241135-How-to-follow-YouTrack-issues-and-receive-notifications if you are not familiar with YouTrack.

1

Please sign in to leave a comment.