Streamlit session attributes reassigned somewhere

Hi,
The streamlit app is running from top to bottom (take a while to fully understand all the implication !)
So if you want the button above to be false, you need to use ‘st.rerun’. (it’s why, the second time, when you press the button, it rerun because there is a changement in the code, the session state as changed, and update the value)

            with col1:
                if st.button("+1", disabled=not st.session_state.submitted):
                    st.session_state.submitted = False
                    st.session_state.count += 1
                    print_log(f"Positive feedback received. New count: {st.session_state.count}")
                    st.rerun()
            with col2:
                if st.button("-1", disabled=not st.session_state.submitted):
                    st.session_state.submitted = False
                    st.session_state.count -= 1
                    print_log(f"Negative feedback received. New count: {st.session_state.count}")
                    st.rerun()

Hope, it helps !

1 Like