I am new to streamlit, and am trying to set query params to be able to share configurations. However, I cannot get the ‘new’ query_params to work at all.
import streamlit as st
st.query_params['test'] = 1
st.write("Done")
st.stop()
The new get_all also doesn’t work, this gives an error st.query_params.get_all("test")
AttributeError: 'dict' object has no attribute 'get_all'
I have checked and I am running 1.30.0 - I get the deprecation warning when using the experimental_* versions, but setting using the new API just doesn’t do anything.
To set query parameters, you should use st.experimental_set_query_params .
import streamlit as st
# Set query parameters
st.experimental_set_query_params(test=1)
st.write("Query parameter set")
To get the current query parameters, use st.experimental_get_query_params .
import streamlit as st
# Access query parameters
params = st.experimental_get_query_params()
test_value = params.get("test", ["default_value"])[0] # Query params are returned as lists
st.write("Test value:", test_value)
Let me know if you might require any further assistance!
This doesn’t seem right? The documentation claims it is an attribute directly on st, not on st.session_state. Also, when I try and access st.session_state.query_params, with a query param in the URL, I get an attribute error.
AttributeError: st.session_state has no attribute "query_params".
It appears an unrelated restart has resolved the issue and it’s all working as expected now! Unsure what was going on but since it’s working, all good.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.