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.