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.
http://blog.nextgenetics.net/?e=102
But what if I only want to hide the first input cell of a notebook?
The @Mathmagician solution is almost perfect, but has many side effects.
More correct would be like:
The call
toggle_code
than may be placed in some code cell before other code, so if code in the cell is executed slowly, won't be side effects. Also it solves the problem with Run Cells and Select/Insert BelowIt adds the toggle button, but the initial state can't be managed
Ok, after trying without success the answers here stated. I found this extension of kirbs.Hide_code nbextension It works just fine. But it is recommended to do the following:
First of all, make sure that you have updated your jupyter, the nbconverter, the nbconverter extensiones and the jupyter serverextension. If you did that then you can do the following in the anaconda prompt (Opened with admin priviledges):
pip install hide_code
jupyter nbextension install --py hide_code
jupyter nbextension enable --py hide_code
jupyter serverextension enable --py hide_code
Finally if you are using anaconda distribution to open your notebooks then make sure of also using these commands:
jupyter nbextension install --sys-prefix --py hide_code
jupyter nbextension enable --sys-prefix --py hide_code
jupyter serverextension enable --sys-prefix --py hide_code
If there are no error on the execution of these commands then you will be able to see and use the hide code options in the toolbar as it is shown here:
Hide_code toolbar
Done! If you use the button for exporting and voilá!
Export Button
Good luck
In case anyone finds excluding all code cells helpful (which is not what is asked here), you can add this flag
nbconvert --TemplateExporter.exclude_code_cell=True
Your solution for hiding all input cells can be altered to affect just a single cell.
Change
'div.input'
to'div.cell.code_cell.rendered.selected div.input'
.This works because when you click the "click here" prompt on a cell's output, that cell becomes the "selected" cell and thus becomes hidden.
If your JavaScript code executes a toggle within the
<script></script>
tags with a line of code like thisthen the block will automatically ("by default") be hidden when the input cell is executed.
Keep in mind that if you do make cell inputs hidden by default, you must run the cell with the Run Cells (Ctrl+Return) option, not the Run Cells and Select/Insert Below options. These will prompt the move of the "selected" label to the next cell before executing the JavaScript, so you may end up hiding a cell that doesn't have the "click here" toggle link in its output. In which case you will have to inspect the cell and navigate through the relevant tags and change
display='none';
todisplay='block';
.Note that this must be put at the end of any code in your cell, and that you need to have imported HTML from IPython.display before executing this code. You can do so by executing
Finally found it's possible using this extension.
https://github.com/ipython-contrib/IPython-notebook-extensions/blob/master/usability/hide_input.js
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
jupyter notebook
localhost:8888/nbextensions
(or whatever port you started on) and activatePrintview
localhost:8888/tree
, create a new notebook and go into itprint("You can see me") #but not me
View
>Cell Toolbar
>Edit Metadata
Edit Metadata
button now showing to the top right of the cell'hide_input':True
to the json e.g. mine looked like{ "collapsed": false, "hide_input": true, "trusted": true }
afterjupyter nbconvert --to pdf --template printviewlatex.tplx notebookname.ipynb
(if your notebook is callednotebookname.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.