Started using Streamlit last week, instant fan. The app I’ve developed is very simple. I am collaborating with a group of scientists (app users) and need to have a simple platform for them to perform quality assessment (QA) review on some data. I use st.form that has some select boxes that lets users select a measurement from the project database for review. Once these options are selected, I have a st.form_submit_button that triggers the app to go get the data from the database based on the user input. It then writes out the data and makes a couple charts for them to look at, and then 2 drop down menus and a text box are provided to allow them to provide their input. A second st.form_submit_button is used to commit their input to the database.
Here’s the issue. This works perfectly in local development using an SQLite database. I updated the app to point to a Postgres database rather than my local test SQLite database. Everything still works perfectly except the second st.form_submit_button. It behaves totally differently now and does not commit anything to the database. Just to check, I put the database commit before the submit button and it commits, but only commits blanks (as if no input). For example, when put before the second submit button this successfully commits blank text ("") to the Postgres database even when there is user input:
CUR.execute("UPDATE table SET euid = ‘userinput1’ WHERE hashid = ‘userinput2’)
DBCON.commit()
While this does not commit anything to the Postgres database, clears the form (with clear_on_submit = False), and starts over without doing anything or raising any errors:
commitbutton = st.form_submit_button(label = ‘Click here to commit changes to database’)
if commitbutton:
CUR.execute("UPDATE table SET euid = ‘userinput1’ WHERE hashid = ‘userinput2’)
DBCON.commit()
Only the second st.form_submit_button is in question here. I haven’t changed anything else about the app except the database that it points to.
I am trying to update sqlite which is embedded database of python. Post submit button values are not going into insert statement in my case also.
I tried printing the values of each input field, no output was observed, however I used st.info(body) to check the values where I could see the values of fields entered in the form. However all the values were showing underlined, type also did not reveal the details.
There is something which is missing here which has not been documented and/or demonstrated by the streamlit team.
In this case I am fairly certain the curs.execute and commit need to be below the form_submit_button. Running the code the way you have it clears the app/form and then puts the list with empty values into the database. I use an if condition, e.g.,
if _submitForm:
curs.execute(…)
conn.commit(…)
This way these get triggered and run before the app refreshes itself on submit.
Hi. Without looking into your code, I don’t know if I can offer specific help. However, I started developing a GitHub page that would demo basic CRUD operations in streamlit. That is linked below (assumes you have a database set up, but the db.py code can create one for you). I want to add more to that repository, but the current app.py code shows a basic structure for do a select and update. One must be careful. It is tricky to get Streamlit working correctly with a database, but it can work nicely.
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.