How to refer to a specific variable or output of a cell in a notebook?


In Jupyter Book, we’d like a language agnostic way to grab the output of a cell in a notebook, and inject it into a page in a book. However, there isn’t an obvious way to do this and we’re considering a few options. I’m curious if anybody in the JupyterLab world has an intuition for what makes sense.

Two things we’re considering

  1. Use the Cell ID. The notebook spec now has the notion of Cell IDs to uniquely refer to a cell. However, there is almost no UI around this, and most Cell IDs are programmatically generated, non-memorable names. The other problem is that you’d still need a way to refer to a specific output of a multi-output cell.
  2. Use user_expressions. The notebook has a concept of user expressions, which is kind-of like a dictionary that stores the results of running expressions in a cell. This could be used to define a unique variable name that has the result of some expression stored in it. However, the UI and documentation around this notebook metadata is also very minimal, and many (most?) kernels don’t implement functionality for this.

Any other ideas?

It seems like any of the options we’ve discussed would require some refinement of either the interfaces, documentation, or metadata around notebooks, so there doesn’t seem to be a single obvious solution.

Are we missing anything obvious? And if not, which of the approaches above seems most reasonable to others?

You can find a discussion laying out some of these (and other) ideas here: