ipython-contrib / jupyter_contrib_nbextensions

A collection of various notebook extensions for Jupyter
http://jupyter-contrib-nbextensions.readthedocs.io/en/latest
Other
5.23k stars 806 forks source link

For a specific cell, output and then hide the output? #600

Open cqcn1991 opened 8 years ago

cqcn1991 commented 8 years ago

In my notebook, I have some inter-result. When I run the notebook, I want to see them, but they are often too long, so I also want to hide them when the output is complete.

For example In https://cdn.rawgit.com/cqcn1991/Wind-Speed-Analysis/master/output_HTML/hongqiao_intl.html#6.2-Cross-validation,-to-select-the-number-of-Gaussian

I have cross validation results

qq

They are important results, I want to see them when the cross validation is running, but they are too long, so when I output the HTML, and show it to others, I want to hide them. And redisplay them when requested.

Is there any way I can do this?

I think a good way is to change the output into a [+] button, and when you click it, the output is shown again.

jfbercher commented 8 years ago

I think that this is an interesting idea and I also missed sometimes such a functionality. I have made a small nbconvert template, here, to try to address this.

Since outputs can be collapsed in the notebook, the idea was simply to detect the collapsed state (available in cell metadata) and then hide/show the output div in the html file using a bit of javascript.

Just put the template in your templates directory and then issue jupyter nbconvert --template collapsed_outputs FILE.ipynb

You can find an example of conversion result here.

cqcn1991 commented 8 years ago

@jfbercher Interesting, I never notice that the collapsing feature in edit mode before. I know there is a collapse feature, but now it behaves quite differently as I remembered.

That's a good discovery for me, thanks.

cqcn1991 commented 8 years ago

Is there any magic command that could used to collapse a cell?