How to convert an ipython notebook to html with collapsed output (and/or input)

后端 未结 3 1334
故里飘歌
故里飘歌 2021-01-19 02:36

I have an ipython notebook I\'d like to share with colleagues who may not have ipython installed.

So I converted it to html with :

ipyth         


        
3条回答
  •  余生分开走
    2021-01-19 03:05

    I found what I wanted thanks to that blog which does exactly what I wanted.

    I modified it a bit to make it work with ipython 2.1 [edit: works aslo with Jupyter], and mixed the input and output hidding tricks.

    What it does:

    When opening the html file, all input will be shown and output hidden. By clicking on the input field it will show the output field. And once you have both fields, you can hide one by clicking the other.

    edit: It now hides long input, and about 1 line is always shown (by defa. You can show everything by clicking on the input number. This is convenient when you don't have output (like a definition of a long function you'd like to hide in your HTML doc)

    You need to add a template while doing nbconvert :

    ipython nbconvert --template toggle my_notebook.ipynb
    

    where toggle is a file containing :

    {%- extends 'full.tpl' -%}
    
    {% block output_group %}
    
    {{ super() }}
    {% endblock output_group %} {% block input_group -%}
    {{ super() }}
    {% endblock input_group %} {%- block input -%}
    {{ super() }}
    {%- endblock input -%} {%- block header -%} {{ super() }} {%- endblock header -%}

    Basically, you can inject whatever javascript and css you want to customize your notebook at will!

    Have fun !

提交回复
热议问题