Closed simon-ging closed 9 months ago
I encountered this same issue, where I change an input value, other states are lost from the URL.
initial url = localhost:8501
* change input a
url = localhost:8501/?a=foo
* change input b
url = localhost:8501/?b=bar (expected localhost:8501/?a=foo&b=bar)
Here's a minimal working code taking radio component as an example:
import streamlit as st
def get_url(key):
qp = st.experimental_get_query_params()
qv = qp.get(key, None)
if qv:
return qv[0]
else:
return None
def update_url(key):
qp = st.experimental_get_query_params()
qp[key] = st.session_state[key]
print('on_change:', qp[key])
st.experimental_set_query_params(**qp)
def url_radio(label, options, key, *args, **kwargs):
def on_change():
update_url(key)
qv = get_url(key)
if key in st.session_state:
qi = options.index(st.session_state[key])
print('get ss:', qi)
elif qv:
qi = options.index(qv)
print('get qv:', qi)
else:
qi = 0
print('get def:', qi)
return st.radio(label=label, options=options, key=key, index=qi, on_change=on_change, *args, **kwargs)
r = url_radio('My radio', ['Me', 'Mine', 'Myself'], key='myradio')
st.write(f"{r=}")
It seems streamlit==1.21.0
fixes this regression.
Hi, widgets need two clicks to update, the get state is lagging behind. Minimum example below, after the second selection change the selection is always one step behind.
Versions streamlit 0.1.20 streamlit-permalink 0.3.0
Currently I am solving this by keeping a "live" version of the get state in st.session_state and only actually using the get parameters on reload, instead of using streamlit-permalink.