-
Notifications
You must be signed in to change notification settings - Fork 293
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
Anywidget Observation: Trigger Cell on Specific Traitlet Changes only #2976
Comments
Thanks for filing the detailed issue and the example! We definitely want to add fine-grained reactivity to anywidget, and haven't gotten to it yet. As a workaround, you maybe be able to create state get_orange, set_orange = mo.state() get_blue, set_blue = mo.state() w =mo.ui.anywidget(CounterWidget(orange_value=42, blue_value=17))
# might need this in another cell
w.observe(set_orange, names='orange_value')
w.observe(set_blue, names='blue_value') Then all references of |
That looks mostly right. Can you try putting observe call in the same cell as the widget |
you can put whatever you want to initialize the state, but putting
There is a status indicator on the right side of the cell for how long it took to run. If you hover over it, you can see when it was last run. We plan to later add a timeline/flame graph of previous cell runs as a sidebar helper. |
Code Exampleimport time
w =mo.ui.anywidget(CounterWidget(orange_value=42, blue_value=17))
get_blue, set_blue = mo.state(None)
w.observe(set_blue, names='blue_value')
print(time.time())
w current_blue = get_blue()
if current_blue is None:
print("Blue state is None (initial state)")
else:
print(f"New blue state is {current_blue.new}")
that works as well! Code Exampleimport time
w =mo.ui.anywidget(CounterWidget(orange_value=42, blue_value=17))
get_blue, set_blue = mo.state(0)
w.observe(set_blue, names='blue_value')
print(time.time())
w current_blue = get_blue()
if not hasattr(current_blue, 'new'):
print("Blue has no new state yet")
else:
print(f"New blue state is {current_blue.new}") |
Description
In my Jupyter notebook (left), I can observe changes to the
blue_value
traitlet and trigger actions accordingly. In my Marimo notebook (right), I want to replicate this behavior so that only changes toblue_value
trigger the next cell execution, while changes toorange_value
do not. After discussing this with @mscolnick on Discord, it seems Marimo currently does not have the fine-grained control needed for this behavior, so I’m opening this issue.Suggested solution
a cell with
print(w.blue_value)
will not be triggered by changingw.orange_value
Alternative
No response
Additional context
Marimo code:
jupyter code:
The text was updated successfully, but these errors were encountered: