I'm looking for a way to hide code cells (inputs) when export my .iipynb file to a HTML. I don't want the code cells to be visible at all (not some button that turn them off/on). The output is for people that have no idea what a programming language is. I tried many things that I found on the internet but nothing seems to work.
Thanks
There are two ways to hide content: To hide Markdown, use the {toggle} directive. To hide or remove code cells or their outputs, use notebook cell tags.
Jupyter Notebook's Built-In Capability: If including code, this is the easiest way to create the JNaaP. This method is as simple as clicking File, Download as, HTML (. html). Jupyter will then download the notebook as an HTML file to wherever the browser defaults for downloaded files.
It seems to be that the shortcuts from jupyter notebook are integrated into the jupyter notebook in visual studio code. If you press "o" on a cell, it will hide the cell output.
Capturing Output With %%capture IPython has a cell magic, %%capture , which captures the stdout/stderr of a cell. With this magic you can discard these streams or store them in a variable. By default, %%capture discards these streams. This is a simple way to suppress unwanted output.
as of now (nbconvert version 5.6.0) the easiest solution seems to be to provide the argument --no-input
when using the CLI interface of nbconvert:
jupyter nbconvert yourNotebook.ipynb --no-input
it works like magic more info here
You can do this with an NBConvert template. Most of the examples out there are for latex/PDF, and won't work with HTML, which uses a different set of templates (and, for some reason, a different extension and slightly different file syntax).
Write the following into a template file called hidecode.tpl
:
{%- extends 'full.tpl' -%} {% block input_group %} {%- if cell.metadata.get('nbconvert', {}).get('show_code', False) -%} ((( super() ))) {%- endif -%} {% endblock input_group %}
Then convert your notebook to HTML with:
jupyter nbconvert --to html --template hidecode YourNotebook.ipynb
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With