I want to store the values of my IPython.html.widgets
in my ipython notebook somehow.
Is there a way to modify the metadata of the current cell from the code within the cell itself?
For notebook level: in the Jupyter Notebook Toolbar go to Edit -> Edit Notebook Metadata. For cell level: in the Jupyter Notebook Toolbar go to View -> Cell Toolbar -> Edit Metadata and a button will appear above each cell.
Just double click on the markdown cell. Edit what you want to and Run. It will reflect the changes. Save your notebook.
When a cell is in edit mode, you can type into the cell, like a normal text editor. Enter edit mode by pressing Enter or using the mouse to click on a cell's editor area.
nbformat contains the reference implementation of the Jupyter Notebook format, and Python APIs for working with notebooks. There is also a JSON schema for notebook format versions >= 3.
I don't know how to do this from within the notebook, but I found a way to do it with a custom preprocessor and nbconvert.
You can create a class that extends nbconvert.preprocessors.ExecutePreprocessor. In the preprocess (or preprocess_cell) method, add logic for storing the relevant output in the cell metadata.
Something like:
class MyExecutePreprocessor(ExecutePreprocessor):
def preprocess_cell(self, cell, resources, index):
# Execute the cell normally
cell, resources = super().preprocess_cell(cell, resources, index)
# Add your magic here
cell.metadata['widgets'] = {'stuff':'that is cool'}
return cell, resources
You can then execute this preprocessor programatically, or as an argument to nbconvert.
If I understand what you are looking for:
from the Cell Toolbar
(top right of the ipython notebook toolbar), select Edit Metadata
from the drop-down list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With