This component is a quick an easy way to offer a User Interface to a database. In just one function, show the data as a st.dataframe with pagination, sidebar filters, autocomplete text fields and handling foreign keys with a st.selectbox and the str representation of the foreign row, instead of the id number.
The page shows a button to create a new row in a dialog and clicking the row opens a dialog to edit or delete it.
To use it, you don’t need to change your sqlalchemy Models definition, just add a str method to them and the relationships, which you should probably have done anyway.
One small suggestion:
When you delete a row, it would be nice if, after showing the “successfully deleted”, it:
Closed the modal
Automatically reloaded the dataframe view so that the deleted row is gone. [This happens after you unclick the row, but it would be nice to have it happen automatically]
You are right, in fact I tried to do this. The problem is that if I reload, it updates but I couldn’t display a notification if the operation was successful. I decided the notification was more important than the update. But it seems this is those situations when the streamlit way of working can be a little tricky, but I plan to tackle this issue.
I was difficult to handle session_state, but finally I could do it. Now After saving or deleting, it closes the dialog and show a st.success or st.warning.
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.