Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving widget state in ipynb #62

Open
miduncan opened this issue Apr 7, 2021 · 4 comments
Open

Saving widget state in ipynb #62

miduncan opened this issue Apr 7, 2021 · 4 comments

Comments

@miduncan
Copy link

miduncan commented Apr 7, 2021

Jupyterlab and Jupyter-classic both support a way to save the notebook such that it persists the widget data in the ipynb (see here). This can be used so that exporting a notebooks will show the widgets with the correct value. It is done by writing to the metadata portion of the ipynb, not by changing the output value saved in the ipynb. My question is

  • Are we open to supporting this in nteract?
  • If yes, how would we want to do it? Since widgets are written as an output, writing to metadata from within an output might be considered a bit of an anti-pattern
@captainsafia
Copy link
Member

captainsafia commented Apr 8, 2021

@miduncan What's the payload that is written to the notebook when using the "Save Notebook Widget State" item?

@miduncan
Copy link
Author

miduncan commented Apr 9, 2021

@captainsafia It looks something like this (irrelevant fields omitted)

{
 "cells": [
  {
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "e628e4cd267741c2a45818fc11314d4b",
       "version_major": 2,
       "version_minor": 0
      },
     },
    }
   ],
  }
 ],
 "metadata": {
    ...
  },
  "widgets": {
   "application/vnd.jupyter.widget-state+json": {
    "state": {
     "e628e4cd267741c2a45818fc11314d4b": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "IntSliderModel",
      "state": {
       "layout": "IPY_MODEL_4e99f641bc7146acb26556cfe7e69521",
       "style": "IPY_MODEL_ea421168b7084ac397e9829f9dc7a77b",
       "value": 50
      }
     },
    },
    "version_major": 2,
    "version_minor": 0
   }
  }
 }
}


@miduncan
Copy link
Author

miduncan commented Apr 9, 2021

As far as not having outputs writing that in a notebook, we could possible store a reference to the Widget Manager somewhere in a redux store. Then we could make the get_state call (seen here) from wherever we want and add that to the notebook. Thoughts?

@captainsafia
Copy link
Member

Yeah, I'm not opposed to the idea on principle but I think the design needs to be fleshed out a little bit more especially because it does require some bidrectional interactions between the parent app and an individual output.

we could possible store a reference to the Widget Manager somewhere in a redux store.

Yeah, maybe we can store a reference to the Widget manager in the transient state of the notebook. It looks like get state will serialize all the widgets in the notebook? How do we make sure that we write the correct serialized version to the output on disk?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants