I’ve made a few streamlit apps now and it’s gone well. But I was wondering how I could read data quicker than I am currently doing. Typically what i do is the user enters some inputs (via some selections) in the left pane, and using this information i read a particular dataframe or set of dataframes that is then cached into the main page. Sometimes I use json files instead of dataframes as well.
is there a better way to do this? I usually also have this kind of setup where the user chooses what data to be shown, then waits for it before playing around with it.
Welcome to the Streamlit community. What you’re doing sounds fine, and is a common model with Streamlit. What specifically are you unhappy about the way you’re doing things or what do you want improved upon?
One thing i had an issue with is if i have multiple selections (inputs) that the user must choose before loading the right data, then as soon as the user clicks one, streamlit retries to load the data. But really i want streamlit to wait until the user has updated all of them.
Should I create a “submit” button where the data is not fetched until this button is clicked? Is this the best way? If so, can someone point to a quick example?
A couple of things for performance unrelated to Streamlit:
Make sure the datasets only contain the columns that are needed for the app. To paraphrase a popular coding statement, the fastest data load is one that never happens
Consider using a binary format instead of CSV/text files. Using something like Parquet or Arrow tables will allow you to keep the data stored in a format that’s much faster to read
Consider using a lightweight database like SQLite, for the same reason as using Arrow or Parquet. Databases are optimized for fast retrieval and computation.
Yes, creating a submit button is best for such a situation. Will you need to maintain state, meaning is it a multi-page app or for whatever reason do you plan to use the SessionState code? If so, I find checkbox a bit more predictable and easy than the button widget.
Thanks for the advice. I am not sure what you mean by “sessionstate code”. Do you have an example that demonstrates how a checkbox would be different in this situation?
I may have needlessly complicated matters/confused you with my session state remark. You can see what I mean with this thread: Programmable State Survey!
If you don’t know or care about session state, a button is perfectly fine. You can always change later if need be.
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.