MyST-NB icon indicating copy to clipboard operation
MyST-NB copied to clipboard

Discuss using notebook-level metadata to glue variables

Open choldgraf opened this issue 5 years ago • 0 comments

Another idea here - could we use notebook-level metadata to define variables that users wish to Glue into the notebook? In the context of jupyter-cache, I believe that the notebook metadata gets passed as well as the code cells (right?) and if so, then we could do something like:

  • Tell users to add notebook-level metadata to define the variables they want "glued" into the notebook, something like:

    {"glue": {"variables": ["var1", "var2"]}}
    
  • After executing the notebook, Jupyter Cache checks the variables listed in the notebook metadata. If it finds a variable listed there, that also is defined at the end of execution, then it calls the kernel's "display" on it, and stores the results with the variable name as the key name (perhaps optionally, notebookname:variablename)

  • These results are also stored as either:

    • notebook-level metadata, e.g. {"glue": {"outputs": {"var1": mimebundle}}}
    • A cell w/ a remove_cell tag that is appended to the bottom of the notebook
  • Then everything after this is the same as how glue currently works

That could potentially be

  • a way to disentangle the "glueing" code from the user's "doing stuff" code
  • a more reproducible behavior for users to understand (since right now they can do glue('mykey', a); a+=1; glue('mykey2', a) which might be confusing). Because each variable is only glued once after execution, it could be obvious what its value is
  • a way to be language agnostic (so users don't need to remember how to glue stuff in one language vs. another, they just need to know to put the right metadata in the notebook and a developer has to define how to call a display function once)

choldgraf avatar Jun 02 '20 01:06 choldgraf