Hey @calvin,
Sorry for the long delay, its been very busy over here! @kmcgrady was able to find some workarounds for your case, here is a trivial example:
import streamlit as st
if st.checkbox("I have something"):
st.write("Checked")
with st.beta_expander("expand"):
a = st.selectbox("Choose 1", ['1','2'])
Open the expander and click the checkbox, expander collapses. This is due to the fact that we add/remove something to the tree before expander when the checkbox occurs…expander essentially “rerenders” with its initial state. If we removed the st.write
call, everything seems to work as expected.
import streamlit as st
st.checkbox("I have something"):
with st.beta_expander("expand"):
a = st.selectbox("Choose 1", ['1','2'])
For the time being, the solution is to either avoid rendering the password placeholder when the password is correct or to always render the placeholder so the “structure” of the page doesn’t page. There’s a couple ways to do it.
One uses `experimental_rerun`:
import streamlit as st
import SessionState
def run():
with st.sidebar:
st.selectbox('Please choose option', ['A', 'B', 'C'])
with st.beta_expander("expand"):
st.selectbox("Choose 1", ['1', '2'])
st.selectbox("Choose 2", ['3', '4'])
if __name__ == "__main__":
st.set_option('deprecation.showfileUploaderEncoding', False)
session_state = SessionState.get(password='')
if session_state.password == '123':
run()
else:
pwd = st.sidebar.text_input(
"Password:", value="", type="password")
if pwd == '123':
session_state.password = pwd
st.experimental_rerun()
elif pwd != '':
st.error("the password you entered is incorrect")
And one moves the `st.sidebar.empty()` to be rendered in any case:
import streamlit as st
import SessionState
def run():
with st.sidebar:
st.selectbox('Please choose option', ['A', 'B', 'C'])
with st.beta_expander("expand"):
st.selectbox("Choose 1", ['1', '2'])
st.selectbox("Choose 2", ['3', '4'])
if __name__ == "__main__":
st.set_option('deprecation.showfileUploaderEncoding', False)
session_state = SessionState.get(password='')
pwd_placeholder = st.sidebar.empty()
if session_state.password != '123':
pwd = pwd_placeholder.text_input(
"Password:", value="", type="password")
session_state.password = pwd
if session_state.password == '123':
pwd_placeholder.empty()
run()
elif session_state.password != '':
st.error("the password you entered is incorrect")
else:
run()
Ken has also opened a ticket to address this use case in future!
Hope this helps!
Happy Streamlit-ing!
Marisa