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
Bad behavior with set_query_params #6907
Comments
Deployed reproducing code here: https://noamgat-streamlit-example-streamlit-app-x1gje6.streamlit.app/ |
I was able to workaround the bug, writing the solution here in case anyone finds it in the future.
|
@noamgat I am not able to reproduce the bug on https://issues.streamlit.app/?issue=gh-6907&choice=c in a Chromium browser exactly as you've described it. However I do remember encountering a similar issue while developing https://github.com/Asaurus1/streamlit-qs/. My understanding there was that the problem stems from the order in which values get saved to the URL vs session state when you force a page reload. The way I got around this in streamlit-qs was to only call |
Interesting. Cool project! Thanks!
…On Fri, Jul 7, 2023 at 7:36 PM Alexander Martin ***@***.***> wrote:
@noamgat <https://github.com/noamgat> I am not able to reproduce the bug
on https://issues.streamlit.app/?issue=gh-6907&choice=c in a Chromium
browser. I do remember encountering a similar issue while developing
https://github.com/Asaurus1/streamlit-qs/. My understanding there was
that the problem stems from the order in which values get saved to the URL
vs session state when you force a page reload.
The way I got around this in streamlit-qs was to *only call
experiemental_set_query_params in the on_change callback function of the
selectbox.* This forces the URL to update "in sync" with session_state
and avoids the issue. Streamlit-qs does some magic on the backend to
basically inject this experimental_set_query_params call ahead of any
custom on_change function you specified, so I think it works pretty
transparently.
—
Reply to this email directly, view it on GitHub
<#6907 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAKFA2DUYRS5BLRJ4SYLXXLXPA3IDANCNFSM6AAAAAAZVNDQAU>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
I had to use a combination of both solutions for it to work for me. I had to use both the def update_query_params():
print("updating to",st.session_state.itrselect)
st.experimental_set_query_params(itr=st.session_state.itrselect)
item = st.selectbox(
"Select an item:",
items,
on_change=update_query_params,
index=itr_index,
key="itrselect",
) |
Checklist
Summary
st.experimental_set_query_params does not always write its value to the browser.
In the following example, the write will fail exactly every other time - the new selection will be discarded every 2nd selection.
Reproducible Code Example
Steps To Reproduce
Expected Behavior
The value is always updated
Current Behavior
The value is not updated every other time
Is this a regression?
Debug info
Additional Information
No response
Are you willing to submit a PR?
(Did not mark because I don't know how to solve the issue...)
The text was updated successfully, but these errors were encountered: