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
Finally found it's possible using this extension.
https://github.com/ipython-contrib/IPython-notebook-extensions/blob/master/usability/hide_input.js
Regarding the output, in Jupiter notebook, there is also an option on the bar:
You can Clear
the output or you can hide it using Toggle
. In both cases, you won't delete any variable calculated inside the cell.
The @Mathmagician solution is almost perfect, but has many side effects.
More correct would be like:
from IPython.core.display import display, HTML
toggle_code_str = '''
<form action="javascript:code_toggle()"><input type="submit" id="toggleButton" value="Toggle Code"></form>
'''
toggle_code_prepare_str = '''
<script>
function code_toggle() {
if ($('div.cell.code_cell.rendered.selected div.input').css('display')!='none'){
$('div.cell.code_cell.rendered.selected div.input').hide();
} else {
$('div.cell.code_cell.rendered.selected div.input').show();
}
}
</script>
'''
display(HTML(toggle_code_prepare_str + toggle_code_str))
def toggle_code():
display(HTML(toggle_code_str))
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 Below
It adds the toggle button, but the initial state can't be managed
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 activate Printview
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 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.