Hi Folks,
I have been thinking of creating a pandas DataFrame from user inputs into streamlit using st.session_state but I didn’t have any sucess … the only things I was abel to do is to store only 1 row and the row is updated everytime I insert a new data into app.
Appreciate your support.
Code:
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_new = pd.DataFrame({'Location': location,
'X': x,
'Y': y,
'Demand': demand,
'From': from_,
'To': to,
'Service': service,
'Vehicle': vehicle,
'Capacity': capacity}, index=[idx])
df= pd.DataFrame(columns=['Location', 'X', 'Y', 'Demand', 'From', 'To',
'Service', 'Vehicle', 'Capacity'])
if run:
st.session_state.df = pd.concat([df, df_new], axis=0)
AgGrid(st.session_state.df)
st.write(df.shape[0])