-
Notifications
You must be signed in to change notification settings - Fork 4k
Add a config option to disable warning for setting both a widget default and its key in session_state #6640
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
Add a config option to disable warning for setting both a widget default and its key in session_state #6640
Conversation
|
Thanks for submitting this! BTW, what was the use case for you where you needed this support to intentionally set both the default and key? Was discussing with @vdonato and we couldn't remember since it had been a while since the original issue was filed. But assuming we have a clear use case, seems like a good way to handle it :) |
|
@sfc-gh-jcarroll, a useful case may be when a component state affects other components, like in this example: import streamlit as st
import matplotlib.pyplot as plt
import numpy as np
st.header("Normal distribution")
col_plot, col_settings = st.columns(2)
MU_DEFAULT, SIGMA_DEFAULT, SAMPLES_DEFAULT = 0.0, 1.0, 1000
if st.button("Set default"):
st.session_state.mu = MU_DEFAULT
st.session_state.sigma = SIGMA_DEFAULT
st.session_state.samples = SAMPLES_DEFAULT
if st.button("Max samples"):
st.session_state.samples = 100_000
with col_settings:
st.slider("Distribution mean", -100.0, 100.0, MU_DEFAULT, key="mu")
st.slider("Distribution standard deviation", 0.01, 100.0, SIGMA_DEFAULT, key="sigma")
st.number_input("Distribution samples", 0, 100_000, SAMPLES_DEFAULT, key="samples")
dist = np.random.normal(st.session_state.mu,
st.session_state.sigma,
st.session_state.samples)
with col_plot:
fig, ax = plt.subplots()
counts, bins, _ = ax.hist(dist, 30, density=True)
ax.plot(bins, 1.0 / (st.session_state.sigma * np.sqrt(2.0 * np.pi)) * np.exp( - (bins - st.session_state.mu) ** 2.0 / (2.0 * st.session_state.sigma ** 2.0)), linewidth=2, color='r')
st.pyplot(fig)Also, I think another case may be a multi-paged application having a dedicated |
|
Thanks, @antonace! |
|
@kajarenc, awesome! Thank you for approving and adding these changes to the project! |
* develop: (22 commits) enzyme -> react-testing-library (Countdown, Modal, ProgressBar) (streamlit#6744) Remove console.log (streamlit#6753) Update `st.data_editor` and `st.dataframe` docstrings (streamlit#6752) Update `st.data_editor` session state format (streamlit#6711) Cypress flaky test fixes (streamlit#6743) Document integer size limit for number_input and slider (streamlit#6724) Change default theme hash on app init (streamlit#6729) Use .genericFonts instead of .fonts to fix bug with theme postMessage. (streamlit#6732) Improve startup performance by lazy loading some dependencies (streamlit#6531) Add support for Altair 5 (streamlit#6618) Update modals (streamlit#6688) Improve docstrings for `ttl` and `max_entries` (streamlit#6733) Improve `st.columns` docstring (streamlit#6727) Removed orphan line in dataframe docstring (streamlit#6734) Fix useIsOverflowing dependency array (streamlit#6731) Remove experimental from data editor (streamlit#6712) Clarify set_page_config docstring and exception message (streamlit#6594) Add a config option to disable warning for setting both a widget default and its key in session_state (streamlit#6640) Add column configuration API for `st.dataframe` and `st.data_editor` (streamlit#6598) Migrate datetime column formatting from date-fns to momentJS (streamlit#6702) ...

📚 Context
Please describe the project or issue background here
What kind of change does this PR introduce?
🧠 Description of Changes
Add bullet points summarizing your changes here
Current:
streamlit.mp4
🧪 Testing Done
🌐 References
Does this depend on other work, documents, or tickets?
Contribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.