My app currently depends on a csv file and continuously updates the file as users interact with the website (as a way to keep track of global variables across different sessions). While this works when I deploy the site locally, I wasn’t sure if it would work if I officially deployed it via github. Would it allow the app to update the csv file stored on Github, and would it update multiple times from the actions of different sessions?
The way the app works is that it keeps track of the last time the data was updated and updates the data whenever a certain time has passed. Since its impossible to store variables globally across sessions I simply store the time as a string in a csv file and read/update whenever necessary. If it works as intended, it should update as different users use the website, but store one single file with the correct dates. For example, if user A interacts with the app, it checks the csv file whether enough time passed, and if it did, it updates the data and updates the date on the csv file. If user B were to access the app a few seconds later, they would see the updated date and the data would not need to refresh.
Would this work? I got it to work locally, but I didn’t want to finish building the app around this idea unless I knew for certain that it would once deployed. Thanks for the help!
While it’s possible, it probably won’t work as you expect. Meaning, it’s possible to make commits to GitHub from a Python script, but it’s generally not how people do things like this. Rather, having an external database (even something as simple as a public Google Sheet) is much easier than programmatically making commits to GitHub.
This is approximately how st.experimental_memo and st.cache work with the ttl argument. Have you tried that?
Hi, thanks for the reply. I looked at st.experimental_memo, and it seems like that would save a variable within each individual session, whereas I need something that can store a variable permanently and one that can be accessed from anyone across different sessions. I’m not sure if theres a function that streamlit supports for this.
As for the google sheets, I do think this is the way to go (much easier and better than my previous soluton). Thanks so much!
Of course the best solution would be some sort of function that streamlit supports, but if im not mistaken, it hasn’t been integrated yet? Would love if I were wrong of course.
st.experimental_memo and st.experimental_singleton are intended to persist data across sessions, such that if you have an expensive operation like loading data only one user will take the cost of the load and future users will get the cached version.
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.