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

feat: mo.query_params #1006

Merged
merged 9 commits into from
Mar 30, 2024
Merged

feat: mo.query_params #1006

merged 9 commits into from
Mar 30, 2024

Conversation

mscolnick
Copy link
Contributor

@mscolnick mscolnick commented Mar 27, 2024

This adds the ability pass query_params to python and keep it in sync with the URL state.

@app.cell
def __(mo):
    query_params = mo.query_params()
    return query_params,


@app.cell
def __(mo, query_params, random):
    # In another cell
    print(random.randint(1, 50))
    search = mo.ui.text(
        value=query_params["search"] or "",
        on_change=lambda v: query_params.set("search", v),
    )
    search
    return search,


@app.cell
def __(mo):
    toggle = mo.ui.switch(label="Toggle me")
    toggle
    return toggle,


@app.cell
def __(query_params, toggle):
    # change the value of a query param, and watch the next cell run automatically
    query_params["has_run"] = toggle.value
    return


@app.cell
def __(mo):
    new_value = mo.ui.text(label="Text to add")
    return new_value,


@app.cell
def __(mo, new_value, query_params):
    append_button = mo.ui.button(
        label="Add to query param",
        on_click=lambda _: query_params.append("list", new_value.value),
    )
    replace_button = mo.ui.button(
        label="Replace in query param",
        on_click=lambda _: query_params.set("list", new_value.value),
    )
    mo.hstack([new_value, append_button, replace_button])
    return append_button, replace_button

Closes #951

  • Reactivity
  • Test wasm support
  • Docs
  • Better example for saving state lots of state in the URL params for read mode

Copy link

vercel bot commented Mar 27, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
marimo-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 29, 2024 11:58pm
marimo-storybook ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 29, 2024 11:58pm

akshayka
akshayka previously approved these changes Mar 29, 2024
Copy link
Contributor

@akshayka akshayka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

The flickering in the smoke test was actually due to a cycle among query parameter getting and setting, so that's expected and not an issue.

@akshayka akshayka merged commit 5383dd9 into main Mar 30, 2024
26 checks passed
@akshayka akshayka deleted the ms/query-params branch March 30, 2024 00:04
Benni-Math pushed a commit to Benni-Math/marimo that referenced this pull request Apr 16, 2024
* feat: mo.query_params

* make query params reactive

* fixes

* wasm

* lint

* fixes

* fix test

* python 3.8 compat fix

* fixes

---------

Co-authored-by: Akshay Agrawal <akshay@marimo.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for URL parameters
2 participants