-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Can't reset selected items (check box, radio buttons) by clearing session.state #3841
Comments
Hi Team, |
@Amey-D , @kantuni , @vdonato , @mesmith027 |
Hey @sachinpatel248 Thanks for reaching out. The team has been busy the past few weeks and is finally catching up a little bit. We are taking a look at this issue and hopefully will have a fix out soon. Stay tuned! 😊 |
Any updates/fixes/solutions put in place to enable this functionality please? |
Not at the moment.
…On Mon, 23 May, 2022, 7:35 pm Dowdtw1, ***@***.***> wrote:
Any updates/fixes/solutions put in place to enable this functionality
please?
—
Reply to this email directly, view it on GitHub
<#3841 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACAJNQQO7XIFS34YOWRBBRTVLOGCRANCNFSM5EVFL6PQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Here is workaround: ctx = get_script_run_ctx()
state_key = ctx.session_state._state._get_widget_id('checkbox')
ctx.session_state[session_key] = val |
I know this is a zombie issue but I was looking at it recently from the link Kamil posted above. I wanted to report that this is intended behavior - deleting the key associated to a widget in session_state is not intended to clear or reset the widget. Here's similar working app code that meets the intent of OP's snippet above - changing the button execution to a callback and setting the key to the expected value instead of deleting it. import streamlit as st
st.set_page_config(layout="wide")
columns = st.columns(4)
columns[0].header("Session State Start")
columns[0].write(st.session_state)
n_check_box = 3
columns[1].header("Sample CheckBox")
for i in range(n_check_box):
label = "check_box_" + str(i + 1)
columns[1].checkbox(label=label, value=False, key=label)
n_radio_button = 2
columns[2].header("Sample Radio Button")
for i in range(n_radio_button):
key = "radio_button_" + str(i + 1)
label = "Radio Selection " + str(i + 1)
values = ["Radio " + str(n) for n in range(n_radio_button)]
columns[2].radio(label, values, key=key)
columns[3].header("Session State End")
columns[3].write(st.session_state)
def clear_selection():
for key in st.session_state.keys():
if key.startswith("radio"):
st.session_state[key] = "Radio 0"
elif key.startswith("check"):
st.session_state[key] = False
st.button("Clear Selection", on_click=clear_selection) |
Summary
Can not clear existing selected items from check box, radio buttons.
Tried to reset my selection by deleting each element in
streamlit.session.state
Steps to reproduce
Code snippet:
Steps :
Clear Selection
buttonExpected behavior:
On clicking Clear Selection all selected items should get clear/reset.
Actual behavior:
Selected data persists
Is this a regression?
Not sure
Debug info
Additional information
Had asked this in streamlit forum https://discuss.streamlit.io/t/clearing-all-selected-items-check-box-radio-buttons-selectbox/16605
The text was updated successfully, but these errors were encountered: