How to enter many input variables in Pluto without triggering a full calculation each time

A very basic question, so I apologize if it’s been dealt with elsewhere - I did look.

Suppose I have some function f(x1, x2, x3, x4, …) that is compute intensive and takes a long time to return. How can I enter specific values of x1, x2, … (some are strings, some are dates, some are numbers) without triggering a full calculation of f every time I type a number in the NumberField box for x1 or use a Select dropdown to choose a date for x2, etc.?

It would not be a problem if each change to a variable halted everything and began a new calculation of f (or all dependent cells, more generally). But that doesn’t seem to be the case: If the Pluto notebook is opened with f(x1 = 0, x2 = 0, …) and I first set x1 =1 and then set x2 = 1 it seems to be the case that Pluto first evaluates f(1,0,…) fully before evaluating f(1,1,…).

This feature, if there isn’t an easy workaround that I (an admittedly unsophisticated user) don’t know about, makes Pluto impractical for many important real-world uses of Julia…

Any help here, O Wise and Wonderful Plutoverse?

Add `confirm` by fonsp · Pull Request #164 · JuliaPluto/PlutoUI.jl · GitHub might be what you’re after?

Wonderful, thank you.

Any further guidance on how to use the combine method? I can’t find the required @htl anywhere and am unclear on what to do. As per the example, I’d love to use a single confirm call to wrap a bunch of NumberFields and Sliders because if I bind and confirm each widget separately then I trigger a separate valuation with each push of the confirm button.

there are various examples here in these docstrings:

I can’t find the required @htl anywhere

That macro comes from the HypertextLiteral package, you’ll need to import that into your notebook. You might not need @htl though if you’re not wanting to do anything fancy, the markdown macro md"" might be enough for your needs:

@bind output confirm(
	PlutoUI.combine() do bind
		1) $(bind(Slider(1:10)))
		2) $(bind(Slider(1:10)))
		3) $(bind(Slider(1:10)))
		4) $(bind(Slider(1:10)))

Thank you both. Got it now… I guess the docstrings are my friend :<

So now I have it working well in a small test notebook. But in the larger notebook for which I want to control calculation I get this error (the rest of the cell shown is long but properly constructed). Any thoughts?

Sorry for the windup. Apparently one of the other packages also had a combine method. Everything works as it should when I’m explicit and use PlutoUI.combine and PlutoUI.confirm.

Thank you both again for your help.

Probably DataFrames.combine and PlutoUI.combine conflicting.

Apparently, I was overly optimistic… The code that uses Pluto.confirm and Pluto.combine works in some notebooks but not in others. There is a problem above and beyond the conflict that arose from not specifying the PlutoUI package for the confirm and combine methods:

Any suggestions?

you don’t need to qualify confirm, only combine: PlutoUI.jl/PlutoUI.jl at main · JuliaPluto/PlutoUI.jl · GitHub

Fair enough, but not the root problem:

how are you importing plutoui? perhaps posting a tiny MWE notebook including the “using” (or import) statement would be good.

also, sometimes there is additional logging statements in the terminal window where you started julia and pluto that reveals more.

Here’s the relevant snippet from the larger notebook that shows the error as well as how I import PlutoUI. You are right that I could have been doing that wrong and should have included it in the original screenshot. I will try to construct a small notebook that illustrates the problem. But I doubt that I will be able to, as I have another notebook for which the identical snippet shown works fine (it differs only in the Children being combined inside the do statement). Additionally, there are no errors or useful logging info displayed in the terminal from which the Pluto notebook was launched (screenshot also attached).

Some more alternatives to the original question:

  1. Use the cell deactivation feature to deactivate your long-running cell, then update all inputs and activate the cell again.

  2. Define all input variables as refs, e.g.

const x1 = ref(0.0)
const x2 = ref(0.0)

f(x1[], x2[])

This way, changes in the x1, x2 values do not trigger execution of f. For triggering it, you may e.g. a button.