using Reactive, Interact, DataStructures
p = Input(3.);
α = @lift p/2;

m = @lift Input(α);
lift(a -> togglebuttons(OrderedDict(["one", "two"], [a,2a]), signal=m), α)

Here if you notice,

typeof(p) == Input{Float64}
typeof(α) == Input{Float64}
typeof(m) == Input{Input{Float64}}

But the `signal` keyword argument needs to be of type Input{Float64} since
the values held by the toggle buttons are Float64 numbers, and so it
crashes.

Now, I don't really understand what you are trying to do with the line m =
@lift Input(α). Could you tell me what the value of m should be according
to your problem be when you select "one" and "two" respectively, i.e in
terms of the value of p?



Now my hunch is that you are trying to do something like this:

Let me start from a vanilla togglebuttons connected to a signal m.


using Reactive, Interact, DataStructures

m = Input(1.0)
x = togglebuttons(OrderedDict(zip(["one", "two"], [1.0,2.0])), signal=m)
display(x)
display(m)

Now m contains either 1.0 or 2.0 depending on user's selection. I imagine
you want to multiply this number to another number taken from another
signal, say α, which you can do like this:

p = Input(3.0)
α = @lift p/2;

product = lift(*, α, m)

product  is now a signal that updates when *either* p or m updates and
holds the value: value(α) * value(m)


Another thing you might be trying to do is set the select one of the toggle
buttons when some other signal updates. Let us examine this.


toggled = Input(1.0)
the_other_signal = .... # Some Float64 signal


x = lift(v -> togglebuttons(OrderedDict(zip(["one", "two"], [1.0,2.0])),
signal=toggled, value_label=v), the_other_signal)

display(x)


Now say you want a signal that updates when *either* the toggle buttons
update or the_other_signal updates, then you will need to merge these two
signals, because the toggle buttons will only update `toggled` if the user
deliberately clicks on it.

so, you would go


my_final_signal_phew = merge(toggled, the_other_signal)

Now you have everything you wanted: The toggle button will update in the
view when the_other_signal changes, and my_final_signal_phew will update
when either the user's selection changes or the_other_signal changes.

I hope that helps!

Reply via email to