read-only cells in ipython notebook

后端 未结 3 785
甜味超标
甜味超标 2021-02-04 03:19

Is there a way to mark a cell in the ipython notebook readonly using the json format in the ipynb file? (E.g., a cell attribute \"readonly\":false or some such.) If

相关标签:
3条回答
  • 2021-02-04 04:07

    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.
    0 讨论(0)
  • 2021-02-04 04:08

    @Richard Ackon's answer is more direct, but DOES NOT WORK in Jupyter Lab:

    The problem is that those menus and options are not present there.

    A different (but not so efficient) alternative:

    1. Open the notebook in an editor.

    2. Look for the cell you want to lock.

    3. Add the following lines to the metadata of the cell:

      "metadata": {
          "trusted": true,
          "editable": false,
          "deletable": false
      }
      
    4. Save and reload the notebook in Jupyter and... Tadah!, your cell can't be modified or deleted.

    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

    0 讨论(0)
  • 2021-02-04 04:23

    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.

    0 讨论(0)
提交回复
热议问题