2nd button forces rerun of app and reinitialize 1st button value

Hi, I’m experimenting with layout and flow to have interesting interactions in my app, and I came through this strange behaviour that I was able to reproduce in the code below.

First a bit of context : My app loads a file, and runs through various steps. I want to hide the latter steps until first steps are done. The flow is controlled with booleans set to False at the beginning and the layout is set with a bunch of st.empty().

A simple flow is as follow : load data > validate data > display button to run further analysis > display button to save analysis results

The issue I have is that the second button resets the app, and the state of the first button.

I was able to reproduce the behaviour with this code :

import streamlit as st

def main():
    IS_VALID = st.checkbox('valid')
    btn_1 = False
    btn_2 = False

    st.write(IS_VALID, btn_1, btn_2)
    btn_ctn_1 = st.empty()
    if IS_VALID:
        btn_1 = btn_ctn_1.button('button 1')

    st.write(IS_VALID, btn_1, btn_2)
    btn_ctn_2 = st.empty()
    if btn_1:
        btn_2 = st.button('button 2')

    st.write(IS_VALID, btn_1, btn_2)


I’d like to understand how to correct or circumvent that issue, thanks