read-only cells in ipython/jupyter notebook
Solution 1
Yes, Use the steps below
- Select view on the menubar
- Point to Cell Toolbar and select Edit Metadata
- An "Edit Metadata" button will appear at the top-right corner of the cell.
- Click on that button and edit the json that pops up. Set the editable key to true of false to get the desired effect.
Solution 2
@Richard Ackon's answer requires adjustments for JupyterLab:
-
Open the Property Inspector.
-
Focus the cell you want to lock.
-
Add the following lines to the Cell Metadata:
{ "trusted": true, "editable": false, "deletable": false }
-
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.
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.
Solution 3
There is an extension for IPython that is supposed to that:
Getting it to work is something else, but it is there.
Related videos on Youtube
jverzani
Updated on September 15, 2022Comments
-
jverzani over 1 year
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? -
Dannid over 8 yearsIt sounds like you've tried to get it to work. If so, could you post advice here?
-
ProsperousHeart over 3 yearsThere is no key. Only some dictionary like reference.