I’m looking for a way to asynchronously restart an embedded notebook in my React web app so that specific visualization cells that animate replay with the runtime.module’s variables recomputed.
In order for this to work in my web app properly it cannot be a replay button inside the observable notebook itself, so it must be a call exposed on runtime, module, or my custom inspector.
I’ve attempted to call runtime._compute() and .computeNow() to no avail, they run but do not cause a re-render of the visualization.
One way to do it is to define an auxiliary viewof cell that the rest of your notebook depends on and then just dispatch an input event to it whenever you want to refresh everything. Here’s a quick demo I cooked up for practice:
I can provide a codesandbox version of what I tried but the fact remains I need a solution that does not require injecting any code into the noteook itself.
I suppose you could use module.redefine to trigger a recomputation by redefining a cell to be equal to its previous definition. (This is effectively what clicking the “Run cell” button in the Observable editor does.)
There should be a hacky way of getting the previous definition from the variable object as well, without having to copy the string from the notebook: runtime/variable.js at main · observablehq/runtime · GitHub if I have time later I’ll see if I can put together an example.