How to use st.session_state to create DataFrame from user Entry

Thank you Shawn_Pereira for the link.

I tried to follow the instructions in the link but still, each time it generates a new row, it doesn’t append to the dataframe.


import streamlit as st
import pandas as pd
from st_aggrid import AgGrid, GridUpdateMode
from st_aggrid.grid_options_builder import GridOptionsBuilder

#---------------- Page Config ----------------
st.set_page_config(page_title='New Way of Making Apps', layout='wide')

with st.form(key='add row', clear_on_submit=True):
    col0, col1, col2, col3, col4, col5, col6, col7, col8, col9= st.columns(10)
    with col0:
        
            idx= st.text_input('Idx')
            
    with col1:
            location = st.text_input('Name')
    
    with col2:
            x = st.text_input('X Coo' )
            
    with col3:
            y = st.text_input('Y Coo' )
            
    with col4:
            demand = st.text_input('Demand' )
            
    with col5:
            from_ = st.text_input('From')
            
    with col6:
            to = st.text_input('To' )
            
    with col7:
            service = st.text_input('Service' )
            
    with col8:
            vehicle = st.text_input('Vehicle' )
            
    with col9:
            capacity = st.text_input('Capacity' )
        
        
    run= st.form_submit_button('Submit')


df = pd.DataFrame(columns=['Location', 'X', 'Y', 'Demand', 'From', 'To',
                          'Service', 'Vehicle', 'Capacity'])


st.session_state.df = pd.DataFrame(columns=['Location', 'X', 'Y', 'Demand', 'From', 'To',
                          'Service', 'Vehicle', 'Capacity'])
 
if run:
    if int(idx) > st.session_state.df.shape[0]: 
        st.session_state.df = pd.concat([df, pd.DataFrame({'Location': location, 
                              'X': x, 
                              'Y': y, 
                              'Demand': demand, 
                              'From': from_, 
                              'To': to,
                              'Service': service, 
                              'Vehicle': vehicle, 
                              'Capacity': capacity}, index=[idx]) ], axis=0)


st.write(st.session_state.df)


st.write(st.session_state.df.shape[0])