How to hide one specific cell (input or output) in IPython Notebook?

后端 未结 10 1513
伪装坚强ぢ
伪装坚强ぢ 2020-11-29 21:53

Is there a way to selectively hide one specific input or output cell in IPython notebook?

I could only find the below code to show / hide all input cells.

h

10条回答
  •  隐瞒了意图╮
    2020-11-29 22:17

    This is now built into nbconvert (as of 5.3.0) using tags.

    Here's an example removing a specific cell from the output. Using this notebook. The example has three cells: a markdown cell, a code cell that will be hidden, and a code cell that will not be hidden.

    1. Add the remove_cell tag to any cells you want to hide using the tag editor built into the notebook or JupyterLab (the specific name "remove_cell" doesn't matter)
    2. Convert with nbconvert

      jupyter nbconvert nbconvert-example.ipynb --TagRemovePreprocessor.remove_cell_tags='{"remove_cell"}'

    Any cells with the tag remove_cell will be removed from the output.

    In addition to entire cells, you can filter just inputs or just outputs:

    • TagRemovePreprocessor.remove_input_tags
    • TagRemovePreprocessor.remove_single_output_tags
    • TagRemovePreprocessor.remove_all_outputs_tags

提交回复
热议问题