Activate Codefolding on Binder

Hey notebook fellows!

I have a public github repo with some notebooks and want to install the codefolding extension to increase readability and fold some config cells. However, I can’t manage to do so.

Here is what I’ve tried. In my repo there is a requirements.txt with this line:
jupyter_contrib_nbextensions
Furthermore, there is a postBuild with

jupyter contrib nbextension install --user
jupyter nbextension enable codefolding/main

When I start Binder, I see that the extension is succesfully loaded:

Enabling notebook extension codefolding/main...
      - Validating: OK

However, after binder is launching, I don’t see any effect of enabling the extension. I don’t see how I can fold cells now - it rather seems to me that the extension is not fully enabled somehow:

Do you guys have any ideas?

These extensions are designed to work with classic notebook, not JuptyerLab or RetroLab notebooks.

thanks for the hint. I see…

Is there a way launch binder by default with the classic notebook option without setting in manually every time?

First to follow-up on something you said in your original post.

Current JupyterLab, which was the first image you posted, has code folding ability built-in by default. To fold a cell:
Click on a code cell to highlight it as active and then click on the blue bar to the left. The code cell will ‘fold’ and be represented by three dots where the code cell was previously. You can ‘unfold’ it by clicking on the dots or on the blue bar again.
If you’d like to see the behavior in the current version, go to Try Jupyter, and click on Try JupyterLab in the center top row. A good notebook to open to try it is the ‘Lorenz.ipynb’ file you’ll see listed on the left after the sessions spins up. (At least that is presently what happens; I think it used to open an example notebook automatically after the session started and perhaps that will return.)

Yes, there is a way to open a Binder session launched via the MyBinder.org system with any interface you choose that is installed. The approach is to specify the correct URL and present that to the user.

By default, both the classic notebook interface and JupyterLab are installed and ready to use in MyBinder-launched sessions.
For opening with the classic notebook interface, you need to edit the URL that is now generated by using the form on the MyBinder.org page. It formerly defaulted to generating a link for the classic notebook interface; however, now the default is to open the more modern and full-featured JupyterLab from the links generated by that form. It remains possible though to edit the URL provided after filling out the form there to the pattern that will specify launching the classic notebook interface.
In summary, to do this you take what the form on the MyBinder.org page gives you for a link to a specific notebook and change the ?labpath= part to read ?filepath=.
NOTE that the basis of this approach had been discussed in-depth in as series of replies here, although now the default URL currently displays ?labpath=. And so you switch labpath to filepath at present. (There were some issues to work out when that original series of posts of the new way to specify the classic interface. Unfortunately, I can no longer edit my posts there.)
In fact, the README there has a number of examples of opening with various interfaces by editing the URL that the MyBinder.org site provides by default at the present time. (Note there are some ways that still work to preserve various ‘legacy’ paths so you may notice there’s some variations on that page, but some of the shortest ways possible now are featured in the approach described first in this reply.)

3 Likes

equivalent functionality (of a gutter with code-folding arrows) is built-in into JupyterLab (certainly in version 3.x and likely earlier) - no need to install anything. Just go to SettingsAdvanced Settings Editor, select notebook and add:

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

For instructions on how to enable it in text editor and other types of cells see this SO question

3 Likes