Extract all cell data from current Jupyter notebook

Jupyter has two options for exporting notebooks to other formats using nbconvert either on the command line or as a library. Both require you to pass the source notebook as input (either as a filename or in JSON data).

What I would like to do is, in essence, the automatic generation of offline reports, i.e. using nbconvert library in notebook to export the same notebook to HTML / PDF at runtime. I'm assuming the export code is in the last cell of the instructions document to ignore that last cell when exporting.

My problem is getting the data. Inside the notebook, I can access code cells through In[1]

, Out[2]

etc., but AFAIK there is no such function for memory cells. There is also no (official) method for capturing the laptop name (attribute __file__

) to pass information this way.

There are many examples to grab all cell data from other laptops - but is there a way to access all cell data from the current laptop?

+3


source to share


1 answer


You can do this with a laptop filename and nbconvert as you suggest. Some client side actions may require extensions, one of which I can imagine is a server extension to convert, and you write a bit of JS in the last cell of the code that, for example, displays a button and sends the laptop back to the server extension converter. Hiding specific cells (like cell Js) that you can do in a convert extension or with cell metadata and nbconvert templates. Given the flexibility of the architecture, there are several ways to do this.



+1


source







All Articles