-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creates a reactive variable that is set to the return value of the function. The value will be updated when any of the reactive variables used in the function change. Example: ```solara import solara import solara.lab a = solara.reactive(1) b = solara.reactive(2) @solara.lab.computed def total(): return a.value + b.value def reset(): a.value = 1 b.value = 2 @solara.component def Page(): print(a, b, total) solara.IntSlider("a", value=a) solara.IntSlider("b", value=b) solara.Text(f"a + b = {total.value}") solara.Button("reset", on_click=reset) ``` z.value will be lazily executed the first time, and will be updated when one of the dependencies changes.
- Loading branch information
1 parent
5b55459
commit bbb7584
Showing
3 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import solara | ||
import solara.lab | ||
|
||
value_reactive = solara.reactive(1.0) | ||
|
||
|
||
@solara.lab.computed | ||
def computed_reactive(): | ||
return value_reactive.value + 1.0 | ||
|
||
|
||
@solara.component | ||
def Page(): | ||
solara.FloatSlider("test", value=value_reactive) | ||
solara.InputFloat("test", value=computed_reactive.value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters