Deleting a key from Session State WILL ~~not~~ revert the widget to a default value
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 64/100
- Issue type
- Documentation
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- python
- Domain
- documentation
Research direction
Start with the widget behavior documentation page and reproduce the provided Python snippet in Streamlit. Compare the observed reset to the current wording about deleting a key from st.session_state. Done means the page accurately explains the behavior and its example no longer contradicts the documented result.
Written by the indexing model from the issue text.
Description
The following statement in the docs dont seem to be true to me. I cant replicate the behaviour stated.
Doc Page: https://docs.streamlit.io/develop/concepts/architecture/widget-behavior
"
Calling a widget command when the widget already exists
When rerunning a script without changing a widget's identity:
Streamlit will connect to the existing frontend and backend parts.
If the widget has a key that was deleted from st.session_state, then Streamlit will recreate the key using the current frontend value. This is because deleting a key from Session State will not revert the widget to a default value.
The widget command will return the current value of the widge
"
Here is the code I used to replicate the stated behaviour:
"
import streamlit as st
st.title("Streamlit Widget Behavior Demo")
if "my_slider" in st.session_state:
del st.session_state["my_slider"]Initialize a widget with a key.,
current_val = st.slider("Move this slider:", min_value=0, max_value=100, value=0, key="my_slider")
Display the current state
st.write(f"The widget command returned:
{current_val}")
st.write("Currentst.session_statecontents:", st.session_state.to_dict())
"
The widget command does return the default value if the related key is deleted beforehand.
Please explain to me why this is the case if I misunderstodd the docs.
- Dominant language
- JavaScript
- Stars
- 178
- Forks
- 705
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 39
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from streamlit/docs
-
docs needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
docs
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
-
docs needs triage
Difficulty 3/5 1-2 days Newbie friendliness 35/100
-
bug needs triage
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
docs needs triage
Difficulty 3/5 1-2 days Newbie friendliness 48/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
HarperFast/skills#96 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Automattic/studio#4908 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
sugarlabs/musicblocks#8847 ·
-
client-controller-update ta-bot-triage team-money-movement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
MetaMask/metamask-mobile#36594 ·