# Pluto --- Function barrier

**URL:** https://discourse.julialang.org/t/pluto-function-barrier/59736
**Category:** Tooling
**Tags:** pluto
**Created:** [April 21, 2021, 1:18pm UTC](https://discourse.julialang.org/t/pluto-function-barrier/59736 "2021-04-21T13:18:51Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Tomas\_Pevny](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomas_pevny/32/25466_2.png) [@Tomas\_Pevny](https://discourse.julialang.org/u/Tomas_Pevny)
#### Post date: [April 21, 2021, 1:18pm UTC](https://discourse.julialang.org/t/pluto-function-barrier/59736/1 "2021-04-21T13:18:51Z")

</div>

Dear all,

I am sure that this was here solved / asked before, but i have not found the answer.  
I am playing with the idea of implementing a visual frontend for Mill / JsonGrinder, which will allow you to upload the training data, tweak a model, and then let you start training. I would like to delay a training, such that it will start after all the stuff like models is finished. Thus, I need something like a barrier. I wanted to implement it using a “Button”, where I would have a start button and the training will start if I change the button. But this does not work, because I cannot assign the value to the variable bind to the button.

Something like:

Cell defining button

```julia
md"""
$(@bind go Button("Train!"))
"""

```

Cell performing training

```julia
if go == "Train!"
	Flux.Optimise.train!((x,y) -> loss(model, x, y), ps, repeatedly(minibatch, iterations), opt)
        go = "finished"
end

```

Does anyone has an idea, how can I achieve this?

Thanks for an answer in advance.

---

<div class="post-metadata">

### Author: ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)
#### Post date: [April 21, 2021, 2:43pm UTC](https://discourse.julialang.org/t/pluto-function-barrier/59736/2 "2021-04-21T14:43:46Z")

</div>

I prefer to use `CheckBox` for execution barriers - it’s a better fit for Pluto’s reactivity model.

```julia
md"""
Train! $(@bind cb CheckBox())
"""

```

```julia
if cb
	"go!"
end

```

---

<div class="post-metadata">

### Author: ![lungben](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lungben/32/12314_2.png) [@lungben](https://discourse.julialang.org/u/lungben)
#### Post date: [April 21, 2021, 4:41pm UTC](https://discourse.julialang.org/t/pluto-function-barrier/59736/3 "2021-04-21T16:41:48Z")

</div>

The functionality to delay execution of specific cells (and their dependencies) will be available in Pluto itself soon - you can try it out here (GUI not final, but should be fully operational):

> <https://github.com/fonsp/Pluto.jl/pull/985>
>
> My first works on #298 
> 
> Still very WIP!
> 
> Use Cases:
> 
> \- give a method to p…revent auto-update of cells which take too long to compute to keep the notebook reactive and/or save computational resources.
> \- step-by-step computations for educational purposes
> 
> Suggestion:
> 
> \- Allow the users to add execution barriers to Pluto cells from inside Pluto.
> \- These barriers block execution of the cell they are added to (i.e. located before the cell) if active.
> \- The barriers should be stored in the notebook.jl file, e.g. as comments.
> \- If the notebook.jl file is executed in Julia (without Pluto), the whole file should run, ignoring execution barriers (there would be no way to turn them off without Pluto anyhow).
> \- If an execution barrier is active, the cell and all cells depending on this cell should be marked gray in Pluto, so that it is obvious that they are not executed.
> \- When deactivating an execution barrier, the corresponding cell and all dependent cells are executed immediately and not grayed out anymore.
> 
> Technical implementation:
> 
> \- \[x\] Execution barrier information (is there a barrier? is it active?) could be added to the Cell structs in the backend.
> \- \[x\] Save this information in notebook.jl files and load it from there
> \- \[x\] Based on which cells are deactivated and the cell dependency information, the backend decides which cells to evaluate in case of changes.
> \- \[x\] Pass the barrier information to the frontend
> \- \[x\] In the frontend, the information whether a cell is grayed out is determined based on the execution barrier information in the Cells and the cell dependency information from #891
> \- \[x\] Frontend functionality for activating and deactivating of execution barriers plus visualization of execution barrirers required.
> \- \[x\] Pass changes in barrier information back to the backend
> \- \[x\] Run cell if its execution barrier is deactivated and it does not depend on any activated barrier
> \- \[x\] Tests?
> \- \[x\] Merge current master (currently not working for me out-of-the-box)
> 
> Note: this PR is based on #891, the first commit specific to this PR is 5975d25.
> 
> 
> \# Try it out!
> 
> \`\`\`julia
> julia\> \]
> pkg\> activate --temp
> pkg\> add https://github.com/lungben/Pluto.jl#execution\_barrier
> julia\> import Pluto; Pluto.run()
> \`\`\`

For usage, you could take a look at my PlutoCon talk:

[![](https://global.discourse-cdn.com/julialang/original/3X/d/7/d7aaaa3a2cac4f4ac6f0f55c40d058f4a44c8c1c.jpeg "Visualizing cell dependencies and execution barriers | Benjamin Lungwitz | PlutoCon 2021") ](https://www.youtube.com/watch?v=UJRRauTR9Qg)

---

<div class="post-metadata">

### Author: ![Tomas\_Pevny](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomas_pevny/32/25466_2.png) [@Tomas\_Pevny](https://discourse.julialang.org/u/Tomas_Pevny)
#### Post date: [April 21, 2021, 4:53pm UTC](https://discourse.julialang.org/t/pluto-function-barrier/59736/4 "2021-04-21T16:53:19Z")

</div>

I was watching your talk and I was thinking about the solution. The checkbox is a neat idea. Thanks a lot.

---

<div class="post-metadata">

### Author: ![ThummeTo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thummeto/32/26105_2.png) [@ThummeTo](https://discourse.julialang.org/u/ThummeTo)
#### Post date: [June 17, 2024, 2:26pm UTC](https://discourse.julialang.org/t/pluto-function-barrier/59736/5 "2024-06-17T14:26:32Z")

</div>

Three years later 🙂

I also use the checkbox-way, the main problem is that the checkbox stays activated after enabling it. So in the example by @Tomas_Pevny the training would start as soon as I check “Train”, but if I change some reactive cells above the “Train” checkbox, a training is triggered for every GUI action.

The intended behavior would be: Check the checkbox, start a single training while also deactivating the checkbox (to prevent triggering many trainings). Is this possible?

Or is there a better way to solve this now?

Thanks!

---

<div class="post-metadata">

### Author: ![werpers](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/werpers/32/42610_2.png) [@werpers](https://discourse.julialang.org/u/werpers)
#### Post date: [June 18, 2024, 7:43am UTC](https://discourse.julialang.org/t/pluto-function-barrier/59736/6 "2024-06-18T07:43:41Z")

</div>

While trying to solve a similar problem I found this thread: [PlutoUI: Trigger long computation only after user sets many parameters and confirms](https://discourse.julialang.org/t/plutoui-trigger-long-computation-only-after-user-sets-many-parameters-and-confirms/112475)

I liked the following:  
(each code block a Pluto cell)

```Julia
using PlutoUI

```

```Julia
parameters = (1,2,3)

```

```Julia
parameters; @bind trigger CheckBox(default=false)

```

```Julia
result = trigger ? sum(parameters) : nothing

```

This setup means that every time you change `parameters` the check box will be recreated unchecked, blocking the computation.

---

<div class="post-metadata">

### Author: ![ThummeTo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thummeto/32/26105_2.png) [@ThummeTo](https://discourse.julialang.org/u/ThummeTo)
#### Post date: [June 18, 2024, 8:12am UTC](https://discourse.julialang.org/t/pluto-function-barrier/59736/7 "2024-06-18T08:12:54Z")

</div>

Ahh, I see! Nice one!

Thanks!

EDIT: Should be marked as solution IMO.
