sagemathinc / cocalc

CoCalc: Collaborative Calculation in the Cloud
https://CoCalc.com
Other
1.16k stars 211 forks source link

jupyter: support "Update Display Data" #2132

Open williamstein opened 7 years ago

williamstein commented 7 years ago

See http://jupyter-client.readthedocs.io/en/latest/messaging.html#update-display-data

@rgbkrk

rgbkrk commented 7 years ago

Example notebook: http://nbviewer.jupyter.org/github/ipython/ipython/blob/6.x/examples/IPython%20Kernel/Updating%20Displays.ipynb

nteract's implementation of this is to keep track of "display paths" which are the key paths to get to an object. Roughly:

// The current output
const keypath = ["notebook", "cellMap", cellID, "outputs", outputIndex]

// Get all the keypaths for this display ID, if there are any
const keyPaths = state.getIn(
  ["transient", "keyPathsForDisplays", displayID], new Immutable.List())
  .push(keyPath);

// Update each output which has that display id
const newState = keyPaths
  .reduce(
    (currState: DocumentState, kp: KeyPath) =>
      currState.setIn(kp, immutableOutput),
    state
  )
  .setIn(["transient", "keyPathsForDisplays", displayID], keyPaths);

Actual source: https://github.com/nteract/nteract/blob/548fa45734b7655aad711195619d3fd407f06d08/src/notebook/reducers/document.js#L165-L211

rgbkrk commented 7 years ago

We have something similar for an update_display_data message