Export individual cell in IPython/Jupyter notebook

后端 未结 1 1413
抹茶落季
抹茶落季 2021-02-05 18:01

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条回答
  • 2021-02-05 18:42

    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. :)

    0 讨论(0)
提交回复
热议问题