Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

read-only cells in ipython/jupyter notebook

Is there a way to mark a cell in the ipython/jupyter notebook readonly using the json format in the ipynb file? (E.g., a cell attribute "readonly":false or some such.) If not, is there a jquery hack to find suppress the double click event in the cell?

like image 343
jverzani Avatar asked Aug 10 '13 14:08

jverzani


People also ask

How do you make a cell non editable in Jupyter Notebook?

For extra protection, before making the cell not Editable , you may wish to make it not Deletable . To do so, select the cell, open the Option Inspector, and uncheck Deletable in the Cell Options > General Properties section. (And while you're there you can then also uncheck Editable .)

How do I lock my Jupyter Notebook?

Locked cells in Jupyter notebooks To confirm, hit the Edit button and exit the pop-up. These cells are now still runnable but can't be edited or deleted anymore. Once you're done editing all the cells that you want to lock, disable the Edit Metadata again by going to View > Cell Toolbar , and selecting None .


3 Answers

Yes, Use the steps below

  1. Select view on the menubar
  2. Point to Cell Toolbar and select Edit Metadata
  3. An "Edit Metadata" button will appear at the top-right corner of the cell.
  4. Click on that button and edit the json that pops up. Set the editable key to true of false to get the desired effect.
like image 128
Richard Ackon Avatar answered Oct 16 '22 13:10

Richard Ackon


@Richard Ackon's answer requires adjustments for JupyterLab:

  1. Open the Property Inspector.

  2. Focus the cell you want to lock.

  3. Add the following lines to the Cell Metadata:

    {
        "trusted": true,
        "editable": false,
        "deletable": false
    }
    
  4. Click on the tick to save the metadata... Tadah!, your cell can't be modified or deleted.

The Property Inspector comes built-in since JupyterLab 2.0 (note it was moved to the right sidebar by default in JupyterLab 3.0). For older JupyterLab versions you would need to modify the notebook file manually.

enter image description here

Unfortunately, the outputs can still be cleared by intentionally selecting that option in the menu bar (Edit > Clear Ouputs). Of course that can only happen if you DO WANT to clear the outputs and not just update them by running the cell.

Source

like image 34
Mr. Duhart Avatar answered Oct 16 '22 14:10

Mr. Duhart


There is an extension for IPython that is supposed to that:

Read Only Cell extension.

Getting it to work is something else, but it is there.

like image 3
oz123 Avatar answered Oct 16 '22 15:10

oz123