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.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.