Hide Code when exporting Jupyter notebook to HTML
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
Solution 1:
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
Solution 2:
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
Solution 3:
In recent versions of jupyter nbconvert
you can use the --no-input
option:
echo 'A Markdown cell with an equation $x=y+1$
```python
1 + 1
```
' | jupytext --to ipynb | jupyter nbconvert --stdin --execute --no-input --to html --output notebook.html
Now if you don't have the --no-input
option, use --TemplateExporter.exclude_input=True
, which is available from version 5.2.1 on.