# Observables for widgets that get rebuilt?

**URL:** <https://discourse.julialang.org/t/observables-for-widgets-that-get-rebuilt/13285>\
**Category:** Web Stack\
**Created:** [August 12, 2018, 10:12am UTC](https://discourse.julialang.org/t/observables-for-widgets-that-get-rebuilt/13285 "2018-08-12T10:12:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raf/32/3383_2.png) [@Raf](https://discourse.julialang.org/u/Raf)\
**Post date:** [August 12, 2018, 10:12am UTC](https://discourse.julialang.org/t/observables-for-widgets-that-get-rebuilt/13285/1 "2018-08-12T10:12:01Z")

</div>

So I have a bunch of models that output the same plots, with parameter control. I want to be able to swap the models and the controller sliders update. Then using the new sliders should update the plots.

I have it mostly working, but it feels hackish, and I’m not sure how you are intended to do this kind of two-step observation process with observables: the model is observed and rebuilds the widgets, and those widgets then need to be observed.

Here I re-declare the observable mapping inside another mapping function:

```julia
function make_sliders(m)
    # extract data for sliders from the model
    params = Flatten.flatten(Vector, m)
    range = Flatten.metaflatten(Vector, m, DynamicEnergyBudgets.range)
    labels = Flatten.metaflatten(Vector, m, fieldname_meta)

    # rebuild the sliders for the new model
    sl = broadcast((x,l,v) -> InteractBase.slider(x[1]:(x[2]-x[1])/200:x[2], label=string(l), value=v), range, labels, params)

    # remap the slider values to another grouped observable
    map!((x...) -> [x...], sliderobs, throttle.(0.2, observe.(sl))...) 

    # remap slider observations (and checks from elsewhere) to update the plot
    map!(make_plot, plt, m, checkobs, sliderobs)
    sl
end
map!(make_sliders, sliders, model);

```

But this ends up with a lot of difficult to diagnose bugs, and doesn’t seem right.

Any ideas from people who understand a little more how observables work?
