Skip to content

Instantly share code, notes, and snippets.

@treuille
Created November 22, 2022 02:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save treuille/427a7359c591adf4685110e34f3af4a9 to your computer and use it in GitHub Desktop.
Save treuille/427a7359c591adf4685110e34f3af4a9 to your computer and use it in GitHub Desktop.
Example of how to access widget state in a callback.
import streamlit as st
with st.echo():
def on_change():
st.write(f"my_selection **(1)**: `{st.session_state.my_selection}`")
my_selection = st.selectbox(
"Select something", ["a", "b"], on_change=on_change, key="my_selection"
)
st.write(f"my_selection **(2)**: `{st.session_state.my_selection}`")
@treuille
Copy link
Author

To see this in action run:

streamlit run https://gist.githubusercontent.com/treuille/427a7359c591adf4685110e34f3af4a9/raw/18c19de9e058d943710308f88d4d16053395c47e/streamlit_app.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment