Different calculations in session_state and number_input

Hello. I have the following GUI

On first input, i input 2000 in Kas di tangan and 1000 in Emas Logam Mulia. Both of Total Aset Investasi and Total Aset Kas are using the same functions.

The question is, why Total Aset Investasi isn’t calculating Emas Logam Mulia?

Then i tried on 2nd attempt:

i input 3000 in Tabungan and 2000 in Reksadana Pendapatan Tetap. This time Total Aset Investasi delayed in calculations while Total Aset Kas calculated correctly on time.

Is text positions affect how calculations work?

I want to put Total Aset Kas and Total Aset Investasi above all fields and calculated correctly on time.

How do i resolve this?

    with st.expander("Aset Lancar"):
        col1,col2 = st.columns(2)
        with col1:
            for komponen in st.session_state.data['Aset']['kategori']['aset_lancar']['Aset Kas']:
                output = st.number_input(komponen,0,key=komponen,format='%g')
                st.session_state.data['Aset']['kategori']['aset_lancar']['Aset Kas'][komponen] = output
            st.subheader("Total Aset Kas: {:,}".format(get_total(st.session_state.data['Aset']['kategori']['aset_lancar']['Aset Kas'])))                
        
        with col2:
            st.subheader("Total Aset Investasi: {:,}".format(get_total(st.session_state.data['Aset']['kategori']['aset_lancar']['Aset Investasi'])))
            for komponen in st.session_state.data['Aset']['kategori']['aset_lancar']['Aset Investasi']:
                output = st.number_input(komponen,0,key=komponen,format='%g')
                st.session_state.data['Aset']['kategori']['aset_lancar']['Aset Investasi'][komponen] = output

Hi @Cignitor

Typically it would be great to share a minimum reproducible example where others in the community may be able to suggest solutions based on the code.

Based on the observed delayed calculation, I think that you can resolve this by using callback functions where your input widgets can be set to call custom functions that you create (to perform a desired task) and which is called upon click (via on_click) or upon changes in the input values of the widget (via on_change).

Hope this helps!

Hi.

The source code can be found here

I have updated the code. I tried calling a call back it returned the same result.
When i move the Total Aset Kas after the number_input, it calculates correctly.
When i move the Total Aset Kas before the `number_input, it doesn’t calculated correctly.
Is different position of the text may return different results?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.