Number input changes its value to previous state when using st.empty()

Hi everyone! I’m new to Streamlit, and I have some difficulties with st.number_input combined with st.empty(). I’ve pasted part of my code to better visualize the problem:

with R0C1:
with R0C2:
    empR0C2 = st.empty()
    R0C2NI = empR0C2.number_input(label="", value=Day0Value, disabled=st.session_state.disable_b0, key="01")
with R0C3:
    if st.button(label="Edit", key="01"):
       st.session_state.disable_b0 = False
       R0C2NI = empR0C2.number_input(label="", value=Day0Value,disabled=st.session_state.disable_b0, key="02")
with R0C4:
    if st.button(label="Save", key="02"):
       st.session_state.disable_b0 = True
       WriteCoalUsageLimited = R0C2NI
       WriteTimeLimited = pd.Timestamp(Day0 - dt.timedelta(1)).isoformat()
       SendToDBlimited(WriteCoalUsageLimited, WriteTimeLimited)
       Df = client.query_api().query_data_frame()
       Df['DATE'] = Df['_time']
       Df['VALUE'] = Df['_value']
       Df = pd.DataFrame(Df, columns=['DATE', 'VALUE'])
       Df = Df.iloc[:-1, :]
       Day0 = (
       Day0Value = int(Df.loc[Df['DATE'] == Day0, 'VALUE'].iloc[0])
       R0C2NI = empR0C2.number_input(label="", value=Day0Value, disabled=st.session_state.disable_b0, key="03")

This code works great but it has one problem, viz when I enter the value I want to save for the first time and I press enter, the value in st.number_inpute changes to its previous value (before clicking the Edit button), but when I edit the value in st.number_input for the second and I press enter the value is correct and only then I can click Save button.
I understand that this behavior is somehow connected with Streamlit refresh and build order, and I’ve tried to solve this with st.session_state and function connected to on_change, but I’ve failed, and I don’t have any further thoughts on how to solve this problem. In advance I would like to thank everyone for creating the Streamlit framework, it’s great and intuitive for creating data analysis visualization dashboards, and apps.

Have a great day,