Export individual cell in IPython/Jupyter notebook

对着背影说爱祢 提交于 2020-01-12 04:52:08

问题


I am able to export the entire notebook as HTML, but I would like to export just a single cell, together with its output.

Is there some way of doing this?


回答1:


One way to do this is to use a custom preprocessor.

I explain how to do this briefly in response to Simple way to choose which cells to run in ipython notebook during run all.

To summarize: you can extend nbconvert.preprocessors.ExecutePreprocessor to create a preprocessor that checks cell metadata to determine whether that cell should be executed and/or output.

I use Jupyter Notebooks for report generation all the time, so I wrote a collection of custom processors to extend nbconvert behavior:

  • meta-language to determine what cells get executed and included in the final report (if/else logic on entire notebook sections)
  • executing code in markdown cells
  • removing code cells from output.
  • taking input arguments from the command line

I haven't had time to wrap these in an distributable extension, but you can see the code here: https://gist.github.com/brazilbean/3ebb31324f6dad212817b3663c7a0219.

Please feel free to use/modify/do-great-things with these examples. :)



来源:https://stackoverflow.com/questions/33517900/export-individual-cell-in-ipython-jupyter-notebook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!