question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

st.experimental_set_query_params() behaves differently locally vs. on sharing.streamlit.io

See original GitHub issue

First 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

  1. 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 via st.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))
    
  2. Run streamlit run app.py. Type localhost:8501?a=b into a browser URL bar. It should look like this:

    image

  3. 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:

    image

  4. Press the button again and note that now the printed query parameters do match the query parameters in the URL bar, as expected.

  5. 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 write a=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.

    image

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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:10

github_iconTop GitHub Comments

1reaction
kmcgradycommented, Jul 27, 2022

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.

0reactions
benlindsaycommented, Jul 27, 2022

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!!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Alignment is different in local version and cloud version
Hello Streamlit! First of all, amazing work on this package, it is great! However, one small issue that i am facing is alignment...
Read more >
How to most easily share your streamlit app locally?
I want the app to be run locally, as we are dealing with private data; Colleagues should not need to have a Github...
Read more >
Session_state does not seem to be working in the cloud
import streamlit as st my_page = st.sidebar.radio('Page ... confusing that Streamlit behaves differently when used locally or in the cloud …
Read more >
Share your app - Streamlit Docs
Now that your app is deployed you can easily share it and collaborate on it. ... You can either directly add viewers from...
Read more >
App Layout Primitives: Columns, Containers & Expanders
st.columns acts similarly to our beloved st.sidebar , except now you ... in ANY element or component available from the Streamlit library.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found