Hello group,
I have app that pulls the from MySQL table and populates a data frame allowing user to make changes to the data.
When the app submits the updated data to database table, it is not getting updated and no errors are being reported either. I’m using SQLAlchemy for the database interaction. Below is the code for the app. Can anyone suggest what am I missing that is preventing the data to be saved back to the table?
Thanks.
import streamlit as st
import pandas as pd
from streamlit import session_state as ss
from sqlalchemy.sql import text
select_conn = st.connection('mysql', type='sql') # Initialize MySQL DB connection.
configset = select_conn.query('SELECT * from AppSettings;', ttl=0) ## Get the app settings
st.subheader("Edit Configurations")
def data_editor_changed():
st.write("edited_rows: ", ss.ed["edited_rows"])
for k in ss.ed["edited_rows"]:
sid,sname,svalue = ss.edit_configset.iloc[k]
st.write(f"Id is: {sid} Name is: {sname} Value is {svalue}")
if len(configset.index) > 0:
ss.edit_configset = st.data_editor(configset,
use_container_width=True,
hide_index=True,num_rows="dynamic",
column_order=['Name','Value'],
key="ed"
)
st.write("edited_rows: ", ss.ed["edited_rows"])
for k in ss.ed["edited_rows"]:
sid,sname,svalue = ss.edit_configset.iloc[k]
st.write(f"Id is: {sid} Name is: {sname} Value is {svalue}")
upd_conn = st.connection('mysql', type='sql') # Initialize MySQL DB connection.
upd_conn.session.execute(text("Update AppSettings set Value = :NVAL where Id = :RID"),params={"NVAL":svalue, "RID":sid})
upd_conn.session.commit()
st.write(ss.edit_configset)