Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable code folding in Jupyter Lab

Running JupyterLab version 3.0.0 and would like to enable code folding (collapse classes, functions etc in Python). I have followed the instructions in this Jupyter Lab github post:

Under Settings / Text Editor, I have these User preferences (right pane):

{
    "editorConfig": {
        "lineNumbers": true,
        "codeFolding": true
    }
}

And I do not see any triangles appearing on the left side of the cells. What else do I need to do in order to enable code folding?

For abundance of clarity, this question pertains to JupyterLab specifically.

like image 604
CarlosE Avatar asked Jan 01 '21 17:01

CarlosE


People also ask

How do you fold a code in Jupyter Notebook?

You CAN collapse an entire cell if you put a #comment at the top of the cell. Jupyter then provides a drop down arrow that will collapse the entire cell.

How do you collapse the output in a Jupyter Notebook?

There is a shortcut for that: use o (that is the letter o) in the command mode to expand/collapse.

How do I enable suggestions in JupyterLab?

Access the Jupyter Menu Simply hit the “Tab” key while writing code. This will open a menu with suggestions. Hit “Enter” to choose the suggestion.

What is Ctrl Z in Jupyter Notebook?

Jupyter lab: ctrl + z shortcut only for selected cell rather than all modified ones. Ask Question.

How do I add a Jupyter Notebook extension?

sudo -E pip install jupyter_contrib_nbextensions Next, add the notebook extension style files to the Jupyter configuration files. sudo -E jupyter contrib nbextension install --sys-prefix Then, you will enable the extensions you would like to use.

How to export Jupyter notebook to HTML without code?

The nbconvert is a perfect tool for exporting Jupyter Notebook to other formats, like HTML or PDF. It has argument --no-input to hide the code in the exported notebook. The example command that converts ipynb file to HTML: The above command with produce my-notebook.html file without code.

How do I install the preprocessor in Jupyter?

The preprocessor is installed when you install the jupyter_contrib_nbextensions package. To activate the preprocessor manually, add the following lines to jupyter_nbconvert_config.py:

How to install Jupyter contrib nbextension in Linux?

sudo -E jupyter contrib nbextension install --sys-prefix. Then, you will enable the extensions you would like to use. The syntax for this is jupyter nbextension enable followed by the path to the desired extension’s main file. For example, to enable scratchpad , you would type the following: sudo -E jupyter nbextension enable scratchpad/main ...


1 Answers

Those instructions are specifically for the text editor, not the notebook interface.

Try this instead, in Settings / Notebook:

{
    "codeCellConfig": {
        "codeFolding": true
    }
}

If you want to enable code folding for Markdown or raw cells, see markdownCellConfig and rawCellConfig respectively.

like image 160
Chris Avatar answered Sep 19 '22 09:09

Chris