Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync st.data_editor to a database #9929

Open
2 tasks done
dtiosd opened this issue Nov 26, 2024 · 3 comments
Open
2 tasks done

Sync st.data_editor to a database #9929

dtiosd opened this issue Nov 26, 2024 · 3 comments
Labels
feature:connections Related to st.experimental_connection and the st.connections module feature:st.data_editor type:enhancement Requests for feature enhancements or new features

Comments

@dtiosd
Copy link

dtiosd commented Nov 26, 2024

Checklist

  • I have searched the existing issues for similar feature requests.
  • I added a descriptive title and summary to this issue.

Summary

I use st.data_editor to connect the data to the table in my database, num_rows="dynamic", and after deleting and adding the table on the page, the table of the corresponding database has not changed, is there a way to synchronize it to the database?

Why?

No response

How?

No response

Additional Context

No response

@dtiosd dtiosd added the type:enhancement Requests for feature enhancements or new features label Nov 26, 2024
Copy link

To help Streamlit prioritize this feature, react with a 👍 (thumbs up emoji) to the initial post.

Your vote helps us identify which enhancements matter most to our users.

Visits

@jrieke jrieke changed the title st.data_editor Add and delete rows Sync st.data_editor to a database Nov 26, 2024
@jrieke jrieke added feature:st.data_editor feature:connections Related to st.experimental_connection and the st.connections module labels Nov 26, 2024
@jrieke
Copy link
Collaborator

jrieke commented Nov 26, 2024

Hey, there's currently no automated way to sync st.data_editor to a database, but we've considered this a few times in the past. You can manually parse the added/deleted rows though and manually write them to your database (they are accessible through st.session_state, see here).

Can I ask for which database specifically you want this and if you have a specific use case in mind?

@dtiosd
Copy link
Author

dtiosd commented Nov 27, 2024

Thank you for your answer. The following are the databases I used and the code. After processing the feedback, I want to delete the information on the page and synchronize this operation to the feedback table in the database.

import sqlite3
import pandas as pd
import streamlit as st

# 连接到数据库
conn = sqlite3.connect('./info.db')

query_feedback = "SELECT username, content, contact FROM feedback"
feedback = pd.read_sql_query(query_feedback, conn)

# 关闭数据库连接
conn.close()

st.data_editor(
    feedback,
    column_config={
        "username": "Username",
        "content": "Content",
        "contact": "Contact",
    },num_rows="dynamic"
)

1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature:connections Related to st.experimental_connection and the st.connections module feature:st.data_editor type:enhancement Requests for feature enhancements or new features
Projects
None yet
Development

No branches or pull requests

2 participants