Hi I have a question, I would like to update the user input, in my database. Unfortunately, this only works locally but not when I share the app. Does anyone have an idea what I may not have considered?
My function looks like this:
def update_sql_database_ger(label):
try:
connection_de = sqlite3.connect('////Users/****/Documents/GitHub/****/G****.db', check_same_thread = False)
cursor = connection_de.cursor()
print("Connected to SQLite")
ID = st.session_state.ID
Gender = st.session_state.gender
Index = str(st.session_state.current_index)
Count = 1
sql_update_query = """Update Hate_speech_ger set Label = ?, Individual_ID = ?, Gender =?, Count = ? where index_id = ?"""
data = (label,ID,Gender, Count, Index)
cursor.execute(sql_update_query, data)
connection_de.commit()
print("Record Updated successfully")
cursor.close()
connection_de.close()
except sqlite3.Error as error:
print("Failed to update sqlite table", error)
The important thing to keep in mind is that GitHub is generally not considered a “drive” in the same way your local computer is, but rather that it’s a version control system. In that sense, when you deploy to Streamlit Cloud, your code is copied from GitHub, but the values aren’t pushed back to GitHub.
So in terms of code deployed on Streamlit Cloud, you should treat it like any other “container” system, in that multiple copies of the code/container might exist at any one time, different users might be on different instances of the app, etc. If you want a pattern like this to work, you need to have a database hosted outside of Streamlit Cloud. A “database” in this example might include something as simple as Google Sheets, writing to Amazon S3/Google Drive, or a full-fledged database instance hosted somewhere.
thanks for your quick reply! I first worked with a google sheet. This sheet was always updated via API… unfortunately this always gave me an API error when too many participants called the API at once… So I thought this would be a better solution… I will think about your suggestions! Thanks a lot for that.
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.