Hello, @Feodoros!
The reason this happens is because the st.button
doesn’t keep its state when the app gets rerun. So, when you change the selectbox, the app gets rerun, and the button is no longer “clicked”. One way to work around this is to switch out the button for a checkbox, and then your code should work fine. But, you can also use st.session_state
to save the fact that the button was ever clicked.
if "clicked" not in st.session_state:
st.session_state.clicked = False
if st.button("Process file") or st.session_state["clicked"]:
st.session_state["clicked"] = True
...
Also, when you change the selectbox, all of the functions inside the if st.button...
will be rerun, so if any of them are slow, or intensive to run, you might want to use st.experimental_memo
to cache them so they don’t need to be rerun every time.