Skip to content
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

Unnecessary cell re-runs on query param change #1171

Open
andrewhill157 opened this issue Apr 18, 2024 · 4 comments
Open

Unnecessary cell re-runs on query param change #1171

andrewhill157 opened this issue Apr 18, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@andrewhill157
Copy link

andrewhill157 commented Apr 18, 2024

Describe the bug

In example below, if you use set to set the value of a particular query param, other cells that access the value of a different query param seem to re-run. This is just a toy example, but in my case this behavior leads to a number of things that will not change at all being re-rendered.

In the example below just push the button and the cell with the sleep(10) that is displaying unrelated text will rerun presumably because query params changed but none of the specific params accessed by this cell have actually changed.

Environment

Using marimo 0.4.0

Code to reproduce

image

import marimo as mo
from random import randint
import time

params = mo.query_params()
time.sleep(10)
text = mo.ui.text(
    label="Enter something to display 🎉",
    value=params["text"] or "",
    full_width=True,
)
text
mo.md(text.value)
button = mo.ui.button(label="Click me to generate a new number")
button
button
my_number = params["number"] or randint(0, 1000)
params.set("number", my_number)
mo.md(f"Your number is {my_number}")
@andrewhill157 andrewhill157 added the bug Something isn't working label Apr 18, 2024
@mscolnick
Copy link
Contributor

This makes sense in the queryparams' current form. We can add a concept of lens to be able to scope down the scope of the reactiveness: e.g get_text, set_text = query_params.lens("text") which gives you a more granular piece of state.

(you might be able to do this today with mo.state() as well)

@andrewhill157
Copy link
Author

Yeah totally, is clear in the docs that this is should currently work (sorry bug probably the wrong label here!). Something like that would definitely be helpful at least in my case. I can take a closer look at mo.state and see if I could make something work with that, my quick initial attempts after looking at the docs weren't successful but also my first time looking at it. Was trying to use getter, setter = mo.state(mo.query_params()) and then interacting with it that way, which may not make sense.

@mscolnick
Copy link
Contributor

mo.state(mo.query_params()) may be equivalent to just mo.query_params() - we can look if lensing is something we can support soon

@akshayka akshayka added enhancement New feature or request and removed bug Something isn't working labels Apr 19, 2024
@andrewhill157
Copy link
Author

Great, thanks for considering!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants