If I understood you correctly, you would like to get the selected date as output, but instead your app returns to the initial state, right ?
This is because of Streamlit’s behaviour of running the app linearly from the very top. Hence, it gets stuck at st.button syntax, and you see no output. A quick workaround, (not ideal) using st.checkbox option. So instead of
Use, check_state = st.checkbox("Start")
One of other possibilities, is to use st.session_state and storing the button’s state.
Hello Avra,
Thank you for getting back,
Indeed, I tried to implement the st.session_state method, even though I encountered a related problem.
Here is the modified code:
Import importlib
import streamlit as st
import time
st.session_state.button_sent = None
dates = ['2021-01-01',
'2021-01-02',
'2021-01-03',
'2021-01-04',
]
btn= st.checkbox ('Start')
placeholder_bar = st.empty()
placeholder_bar.progress(0)
placeholder_bar.progress(30)
time.sleep(5)
placeholder_bar.progress(50)
st.write(st.session_state.button_sent)
if btn or st.session_state.button_sent:
st.session_state.button_sent = True
st.write('123')
##option 1
output = st.multiselect('Test', options = dates)
st.write(output)
the print after the select works well, but the problem is that whenever I select now the options from the select box the whole page refreshed and the first couple of lines (before the select box) re run.
Sure, here I put simple examples with progress bar (0, 30, 50) but in my case the code prior to multiselect button takes more time and I find it weird to re run it on every multiselect selections.
So, the possible workaround is , if you wrap around those lines of code prior to multi select as a single function, and use @st.experimental_memo . Please do refer to the doc.