read-only cells in ipython/jupyter notebook

17,000

Solution 1

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.

Solution 2

@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

Solution 3

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.

Share:
17,000

Related videos on Youtube

jverzani
Author by

jverzani

Updated on September 15, 2022

Comments

  • jverzani
    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?

    • Viktor Kerkez
      Viktor Kerkez over 10 years
      There is currently no such feature 2125 and 3469 You could probably do something with the CodeMirror since it supports read only edit fields...
    • jverzani
      jverzani over 10 years
      Very helpful, thanks!
  • Dannid
    Dannid over 8 years
    It sounds like you've tried to get it to work. If so, could you post advice here?
  • ProsperousHeart
    ProsperousHeart over 3 years
    There is no key. Only some dictionary like reference.