-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: run_button #1514
feat: run_button #1514
Conversation
Adds `mo.ui.run_button()`, which can be used to trigger computations when a button is pressed and ONLY when a button is pressed. When the button is pressed, its value is set to `True` and its descendants are run. After its descendants have run, marimo automatically sets the button's value back to False. In this way, cells can gate computations on `run_button.value` -- updates to other variables won't spuriously cause the cell to run. Caveat: The button's value is only reset to `False` when the runtime is configured to autorun cells, since the lazy runtime doesn't know when the button's descendants will/have been run. This should be fine in practice, since `ui.run_button` has no real use in lazy kernels anyway.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
def _on_update_completion(self) -> None: | ||
"""Callback to run after the kernel has processed a value update.""" | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method acts as a post execution hook; the runtime calls it after setting UI element values.
if isinstance(ctx, KernelRuntimeContext) and ctx.lazy: | ||
# Resetting to False in lazy kernels makes the button pointless, | ||
# since its value hasn't been read by downstream cells on update | ||
# completion. | ||
# | ||
# The right thing to do would be to somehow set to False after | ||
# all cells that were marked stale because of the update were run, | ||
# but that's too complicated. | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Special case for lazy kernels, since we don't when descendants will run
docs/api/inputs/run_button.md
Outdated
|
||
@app.cell | ||
def __(): | ||
mo.stop(b.value, "Click `run` to submit the slider's value") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be mo.stop(not b.value)
.
not sure if this hides to much, but could put a stop on the button too?
b.stop(fallback=None)
# Run thing
or maybe b.gate()
, b.clicked()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops yes it should.
Something like that could be nice — maybe b.gate()
... might add in a follow-up
📝 Summary
Adds
mo.ui.run_button()
, which can be used to trigger computations when a button is pressed and ONLY when a button is pressed.🔍 Description of Changes
When the button is pressed, its value is set to
True
and its descendants are run. After its descendants have run, marimo automatically sets the button's value back to False. In this way, cells can gate computations onrun_button.value
-- updates to other variables won't spuriously cause the cell to run.Caveat: The button's value is only reset to
False
when the runtime is configured to autorun cells, since the lazy runtime doesn't know when the button's descendants will/have been run. This should be fine in practice, sinceui.run_button
has no real use in lazy kernels anyway.The implementation reuses the frontend plugin for
mo.ui.button()
.📋 Checklist
📜 Reviewers
@mscolnick