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

后端 未结 10 1520
伪装坚强ぢ
伪装坚强ぢ 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:28

    Here's a method that allows you to hide cells from the HTML/PDF output by editing the cell metadata only.

    Versions I'm using:

    $ jupyter notebook --version

    4.1.0

    $ jupyter nbconvert --version

    4.2.0

    1. Download the ipython notebook extension templates by following install instructions on Github: pip install https://github.com/ipython-contrib/IPython-notebook-extensions/tarball/master
      • This just install files into your local jupyter data directory. Full details in the readme
    2. run jupyter notebook
    3. go to localhost:8888/nbextensions (or whatever port you started on) and activate Printview
    4. go back to localhost:8888/tree, create a new notebook and go into it
    5. create a code cell with some code in it that produces output e.g. print("You can see me") #but not me
    6. go to View > Cell Toolbar > Edit Metadata
    7. click the Edit Metadata button now showing to the top right of the cell
    8. add 'hide_input':True to the json e.g. mine looked like { "collapsed": false, "hide_input": true, "trusted": true } after
    9. save notebook
    10. go back to the terminal and execute jupyter nbconvert --to pdf --template printviewlatex.tplx notebookname.ipynb (if your notebook is called notebookname.ipynb.ipynb)

    You should now have a document called notebookname.pdf in the directory. Hopefully it should have just the text You can see me in it...fingers crossed.

提交回复
热议问题