Interdependent Widgets in one Cell

Hi everyone,

I am quite new to Pluto and I am a little stuck. Also I don’t know how to properly include Pluto code here, if this is possible, please tell me.


Core Problem:

As to my question: In principle I want to access the value of a Slider in the same cell the Slider is defined; let’s say as the maximum value of another Slider. Ideally I want to do this inside a combine environment. So my aim is something like this:

function test()

	return combine() do Child
		md"""
		$(Child("First", @bind maxVal Slider(1:10, show_value=true, default=5)))
		$(Child("Second", Slider(1:maxVal, show_value=true)))
		"""
	end

end

What happens now is that the second Slider correctly starts with the range 1:5 but does not adjust it as I change the first Slider.

I also tried to implement this in a simpler Version without combine like this

md"""
$(@bind maxVal Slider(1:10, show_value=true, default=5))
$(Slider(1:maxVal, show_value=true))
"""

This does however behave in the same way. Weirdly enough I had a notebook where the latter still worked as intended but now I cannot replicate the behavior.

Is what I want to do possible in Pluto? I would greatly appreciate any help.

I know that in this case it is easily fixed by just splitting to two cells. Therefore I included some further context to show why I am interested in this in the first place.


Motivation

I would like it in one cell for two reasons:

  1. The actual code I have in mind is much more complicated and I would like to reuse test() in a number of places. So having it in one function is much more convenient.

  2. I actually want to have a variable controlling how often test() appears. So what I actually have in mind is

function multi_test(n)

	return combine() do Child
		inputs = [
			md"""
			Test $i : $(Child(test()))
			"""
			for i in 1:n
		]

		md"""
		$inputs
		"""
	end
end

In this case all three ‘first’ Sliders also behave the same due to the @bind of maxVal in test(), which is an additional problem.

Thanks again for any help you can offer!

1 Like

I have the exact same problem… I’m also pretty sure that something like this

md"""
$(@bind maxVal Slider(1:10, show_value=true, default=5))
$(@bind otherVal Slider(1:maxVal, show_value=true))
"""

worked before, i.e. that changing maxVal would automatically update the limit of otherVal in the same cell.

But I also can’t reproduce that right now. Funnily enough, trying to start an older Pluto server (e.g. version 0.16) just results in an empty browser window on macOS / Julia 1.8.5 …

Instead I seemed to remember an Issue or a draft PR where the use of depending widgets all from the same cell was currently not supported.
I have tried briefly to look for it between Pluto and PlutoUI issues/PRs but couldn’t find it…

Maybe @fonsp or @Pangoraw might chime in

1 Like

Very interesting, thanks for the info! I guess it makes sense that it’s not supported, but my memory of using this “feature” is pretty vivid – I’m starting to doubt my sanity :sweat_smile: