Below is a simple way for streamlit to display a table from a postgres database. However, I am having issues finding a way to push the edited data in edited_df back into the postgres table.
Additionally, even though it should be possible to push the edited_df back into the table, is there a way to safely do this with ~7 people on the app updating different parts of the table?
import streamlit as st
conn = st.connection("postgresql", type="sql")
df = conn.query('SELECT * FROM "table1";')
edited_df = st.data_editor(df)
Thanks for sharing this question! If you set a key for st.data_editor, any changes made to your dataframe will be stored in Session State – here’s an example of how to access edited data using Session State:
st.data_editor(df, key="my_key", num_rows="dynamic") # 👈 Set a key
st.write("Here's the value in Session State:")
st.write(st.session_state["my_key"]) # 👈 Show the value in Session State
Is the concern with concurrency that users would be updating the table without seeing updates recently made by other users? Or is it more about avoiding having multiple users writing to your database at the exact same time?
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.