st.experimental_set_query_params() behaves differently locally vs. on sharing.streamlit.io
See original GitHub issueFirst of all, thanks for all the work you all do! Just tried streamlit sharing and it is really nice. Keep up the awesome work!
Summary
Locally, st.experimental_set_query_params()
changes the query parameters in the URL bar, but doesn’t trigger a refresh or rerun of the script. On sharing.streamlit.io it seems like it does.
Steps to reproduce
-
Create
app.py
with the content below. This app prints the current query parameters, then allows you to create your own query parameter string to pass into the URL viast.experimental_set_query_params()
. This code also lives at https://github.com/benlindsay/streamlit-sharing-query-params# app.py from urllib.parse import urlencode, parse_qs import streamlit as st initial_query_params = st.session_state.get("initial_query_params") query_params = {k: v[0] for k, v in st.experimental_get_query_params().items()} if not initial_query_params: initial_query_params = query_params.copy() st.session_state["initial_query_params"] = initial_query_params.copy() st.write("Initial query params of the session:", initial_query_params) st.write("Query params before setting new ones:", query_params) new_query_string = st.text_area("New query params string (like 'a=b&c=d')", value=urlencode(initial_query_params)) if st.button("Set new query params without starting new session"): st.experimental_set_query_params(**parse_qs(new_query_string))
-
Run
streamlit run app.py
. Typelocalhost:8501?a=b
into a browser URL bar. It should look like this: -
Type
a=b&c=d
into the text area and press the button. The URL updates, but the query parameters printed above don’t change, as expected. Looks like this: -
Press the button again and note that now the printed query parameters do match the query parameters in the URL bar, as expected.
-
Now deploy this app to
sharing.streamlit.io
and repeat the steps on the deployed app. I have it deployed to https://share.streamlit.io/benlindsay/streamlit-sharing-query-params/main/app.py. So start with https://share.streamlit.io/benlindsay/streamlit-sharing-query-params/main/app.py?a=b, then writea=b&c=d
in the text area and click the button. This time, the query params higher up in the page change as well, as though the script was rerun after setting the query parameters at the end.
I noticed this when trying to get a bootstrap tabs hack working in streamlit sharing. The code for the tabs test is here: https://github.com/benlindsay/streamlit-sharing-tabs and it’s deployed to here: https://share.streamlit.io/benlindsay/streamlit-sharing-tabs/main/app.py. In the code, I always set the query parameters at the end. When running locally, this works fine, but because of the rerun on sharing, clicking on any of the tabs leads to a not-quite-infinite loop.
Is this a regression?
This is my first try at streamlit sharing, so I don’t know.
Debug info
- Streamlit version: 0.85.1
- Python version: 3.9.1
- Using pip
- OS version: OSX Mojave 10.14.6
- Browser version: Chrome Version 90.0.4430.212 (Official Build) (x86_64)
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:10
Hey @benlindsay, @madshaven, and @nflaig I think we were able to get this closer to similar state. Feel free to test it out. I am going to close this ticket as fixed. Let me know if you see something.
Awesome! I just checked my demo apps I shared above and they both ha e the expected behavior without my having to change anything. Thanks!!