Dynamic Multi Select Filters for Streamlit
Custom component to create dynamic multiselect filters in Streamlit. The filters apply to a dataframe and adjust their values based on the user selection (similar to Google Sheets slicers or Only Relevant Values in Tableau).
Basic documentation is available at https://arsentievalex.github.io/streamlit-dynamic-filters/
How to install and use the package:
-
Install the package using pip:
pip install streamlit-dynamic-filters -
Import the
DynamicFiltersclass:from streamlit_dynamic_filters import DynamicFilters -
Create an instance of the
DynamicFiltersclass and pass the dataframe and the list of fields that will serve as filters:dynamic_filters = DynamicFilters(df, filters=['col1', 'col2', 'col3', 'col4']) -
Display the filters in your app:
dynamic_filters.display_filters() -
Display the filtered dataframe:
dynamic_filters.display_df()
Sample usage with sidebar filters:
import streamlit as st
import pandas as pd
from streamlit_dynamic_filters import DynamicFilters
data = {
'region': ['North America', 'North America', 'Europe', 'Oceania',
'North America', 'North America', 'Europe', 'Oceania',
'North America', 'North America', 'Europe', 'Oceania'],
'country': ['USA', 'Canada', 'UK', 'Australia',
'USA', 'Canada', 'UK', 'Australia',
'USA', 'Canada', 'UK', 'Australia'],
'city': ['New York', 'Toronto', 'London', 'Sydney',
'New York', 'Toronto', 'London', 'Sydney',
'New York', 'Toronto', 'London', 'Sydney'],
'district': ['Manhattan', 'Downtown', 'Westminster', 'CBD',
'Brooklyn', 'Midtown', 'Kensington', 'Circular Quay',
'Queens', 'Uptown', 'Camden', 'Bondi']
}
df = pd.DataFrame(data)
dynamic_filters = DynamicFilters(df, filters=['region', 'country', 'city', 'district'])
with st.sidebar:
st.write("Apply filters in any order 👇")
dynamic_filters.display_filters(location='sidebar')
dynamic_filters.display_df()
Demo GIF:
Sample usage with columns:
import streamlit as st
import pandas as pd
from streamlit_dynamic_filters import DynamicFilters
data = {
'region': ['North America', 'North America', 'Europe', 'Oceania',
'North America', 'North America', 'Europe', 'Oceania',
'North America', 'North America', 'Europe', 'Oceania'],
'country': ['USA', 'Canada', 'UK', 'Australia',
'USA', 'Canada', 'UK', 'Australia',
'USA', 'Canada', 'UK', 'Australia'],
'city': ['New York', 'Toronto', 'London', 'Sydney',
'New York', 'Toronto', 'London', 'Sydney',
'New York', 'Toronto', 'London', 'Sydney'],
'district': ['Manhattan', 'Downtown', 'Westminster', 'CBD',
'Brooklyn', 'Midtown', 'Kensington', 'Circular Quay',
'Queens', 'Uptown', 'Camden', 'Bondi']
}
df = pd.DataFrame(data)
dynamic_filters = DynamicFilters(df, filters=['region', 'country', 'city', 'district'])
st.write("Apply filters in any order 👇")
dynamic_filters.display_filters(location='columns', num_columns=2, gap='large')
dynamic_filters.display_df()
Demo GIF:
0.1.9 - 2nd August 2024
Added
- Key for each elements in filters, so that multiple DynamicFilters can be used in one app (contribution by @vikashgraja)
- reset_filters function (contribution by @ragchuck)
0.1.6 - 27th March 2024
Added
- Sorted alphabetically filter labels
0.1.5 - 28th December 2023
Added by kzielins kzislinsk@gmail.com
- Hierarchical filter selectors
- Independent filters with diffrent sessions name
0.1.3 - 28th September 2023
Added
- Ability to specify filter location in display_filters(). The filters can be either displayed in sidebar, main area or columns.
- Error handling of invalid arguments in display_filters().
Changed
- Renamed filter_except() to filter_df(). The function returns a filtered df.
Fixed
- The StreamlitApiException that occured when selected values did not exist in the dataset.
- Possibility to have more than one filter
Metadata
Release files for streamlit-dynamic-filters 0.1.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| streamlit_dynamic_filters-0.1.9.tar.gz | 7.6 kB | Without provenance | Details for streamlit_dynamic_filters-0.1.9.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| streamlit_dynamic_filters-0.1.9-py3-none-any.whl | Python 3 | none | any | Details for streamlit_dynamic_filters-0.1.9-py3-none-any.whl |
Total release size: 14.4 kB
Release files / streamlit_dynamic_filters-0.1.9.tar.gz
| Download URL | streamlit_dynamic_filters-0.1.9.tar.gz |
|---|---|
| Size | 7.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ef65029ec249a3681390711b88fcad339bb3a4ce1e13857443d4553592e23cba
|
|
BLAKE2b-256 checksum How to use checksums |
a830f925349c2ba434b3c271811cbf4a4589828e34af69c0a132738650f98cdc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.3
|
Release files / streamlit_dynamic_filters-0.1.9-py3-none-any.whl
| Download URL | streamlit_dynamic_filters-0.1.9-py3-none-any.whl |
|---|---|
| Size | 6.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0b2d6db612f35bf10e18f19de137c65b051d38ed000a6e3bfe973370b142b42d
|
|
BLAKE2b-256 checksum How to use checksums |
4381bce6dd65a9abb74e5319d3da4604e735791b6044b16744164bcd9a8a9f04
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.3
|
Security for streamlit-dynamic-filters 0.1.9
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.