Is it possible to use variables in Pluto sliders?

So far I am loving the interactivity in Pluto notebooks, but I am frequently hitting a roadblock in setting up sliders. I find I have to manually set the slider range like this

begin
	number_slider = @bind number html"<input type=range min=1 max=111>"
	md"**Number: $number_slider **"
end

Ideally, I would like to be able to dynamically set the min/max,

begin
    minval = 4
	maxval = 111
	number_slider = @bind number html"<input type=range min=$minval max=$maxval>"
	md"**Number of cases: $number_slider **"
end

however, the above code just reverts to the default range of 0 to 100.

Is there a way to dynamically set the slider range (so that I can tie it to things like array length)?

2 Likes

You can use PlutoUI:

https://github.com/fonsp/PlutoUI.jl

number_slider = @bind number PlutoUI.Slider(minval:maxval)
4 Likes

Ahhhh, I suppose I should have checked there first. That’s fantastic. Thanks!

1 Like