About reactivity

I’ve had this problem with a few notebooks now and can’t seem to get things set up right…

I’d like to be able to adjust the slider bars on the top without having the simulation reset each time. I understand it’s happening because of the dependency graph but can’t seem conceptualize any way around it so far. (I did find an example with a slider bar as an actual svg element but it was a bit beyond me right now).


The easiest option is to note that you can reference a value X defined by a view without getting a direct dependence by calling “viewof X.value” instead of “X”. Here’s a fork of your notebook which gets at the behavior you desire:

(The slogan is apparently Views are mutable values.)

Another option to be aware of is Observable’s “this” syntax, which you can use to have a cell “remember” its previous state whenever it is re-evaluated:

This is useful for cells which update themselves only when changes to the input occur, unlike your example, which is constantly checking the inputs with a loop.

See e.g. the main “viewof pic” cell in:

1 Like

Thank you!