Hi everyone,
I’m building a Streamlit app that connects to a PostgreSQL database and uses @st.cache_resource to cache the database connection. The app displays data across multiple tabs, with various filters applied to each data table (e.g., by Client ID, Name, Date Range, etc.).
Here’s my issue: when multiple users access the app simultaneously, the filter selections don’t work independently. If one user applies filters, it seems to override the filters for others, resetting filter selections for other users.
Has anyone faced a similar issue or can offer best practices for handling this?
I have seen some people facing issues like this due to bugs in their code. Best practice is avoiding mixing application-scoped state and session-scoped state, which is in itself quite a broad topic. I don’t think more specific advice can be provided based on your high level description.
def get_clients():
clients_dao = ClientsDAO()
data = clients_dao.get_clients()
return data
def load_clients():
clients = get_clients()
client_data_to_skip = {"outbound_file_types", "inbound_file_types", "transactions", "subscription"}
clients_data = [c.to_dict() for c in clients]
clients_data = [{k: v for k, v in data.items() if k not in client_data_to_skip} for data in clients_data]
clients_df = pd.DataFrame(clients_data)
clients_df["id"] = clients_df["id"].astype(int)
clients_df = clients_df.sort_values(by="created_at", ascending=False)
return clients_df, clients
I ran your code with my own implementation of ClientsDAO and was unable to reproduce the issue. The filters selected in different sessions remain separated, as well as the filtered data.
That is the scenario I tested. Well, unless I am misunderstanding what you mean by “two users filter at the same time” . Because filtering is a matter of a click, if you mean two users clicking the same widget within the same tenth of a second, then no. Should I?
Yes, at the same moment in time. When two users start working with a multiselect filter at the same time. User1 starts selecting items in the multiselect and at the same time user2 starts selecting. In my case, user2’s filters just reset from time to time
No way. It works as expected for me even when two users are changing the same multiselect at the same time. Furthermore, I don’t see how the code you posted can possibly cause the issue.
One thing that might make the widgets reset is changing the data while the app is being used, but the application doesn’t do that so it would be unrelated to simultaneous users of the application.
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.