solara
solara copied to clipboard
Reacton/use_thread issue
Running this, and hitting compute triggers a keyerror in reacton. The fix is to put str(../)
around the last line, but that should not be needed.
import solara
import time
process = solara.reactive(0)
def heavy_compute():
for i in range(10):
print("Computing...", i)
process.value = i
time.sleep(0.1)
return 42
@solara.component
def Page():
compute = solara.use_reactive(False)
result_using_reactive = solara.use_reactive(None)
def maybe_do_compute():
if compute.value:
result_using_reactive.value = heavy_compute()
compute.set(False)
result = solara.use_thread(maybe_do_compute, dependencies=[compute.value])
solara.Button("Compute", on_click=lambda: compute.set(True))
solara.Button("Cancel", on_click=lambda: compute.set(False))
if result.state == solara.ResultState.RUNNING:
solara.ProgressLinear(process.value * 10)
if result_using_reactive.value:
solara.Text(result_using_reactive.value)