# Dynamic Multi Select Filters for Streamlit
[![Open Demo App](https://static.streamlit.io/badges/streamlit_badge_black_white.svg)](https://dynamic-filters-demo.streamlit.app/)
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/](https://arsentievalex.github.io/streamlit-dynamic-filters/)
How to install and use the package:
1. Install the package using [pip](https://pypi.org/project/streamlit-dynamic-filters/):
```pip install streamlit-dynamic-filters```
2. Import the `DynamicFilters` class:
```from streamlit_dynamic_filters import DynamicFilters```
3. Create an instance of the `DynamicFilters` class and pass the dataframe and the list of fields that will serve as filters:
```dynamic_filters = DynamicFilters(df, filters=['col1', 'col2', 'col3', 'col4'])```
4. Display the filters in your app:
```dynamic_filters.display_filters()```
5. 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:
<img src="https://i.postimg.cc/x1zDwgwh/dynamic-filters-demo-1.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:
<img src="https://i.postimg.cc/gkLTjjg6/dynamic-filters-demo-2.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 <Krzysztof Zielinski> 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
Raw data
{
"_id": null,
"home_page": "https://github.com/arsentievalex/streamlit-dynamic-filters",
"name": "streamlit-dynamic-filters",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "streamlit, custom, component",
"author": "Oleksandr Arsentiev",
"author_email": "arsentiev9393@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/a8/30/f925349c2ba434b3c271811cbf4a4589828e34af69c0a132738650f98cdc/streamlit_dynamic_filters-0.1.9.tar.gz",
"platform": null,
"description": "# Dynamic Multi Select Filters for Streamlit\n[![Open Demo App](https://static.streamlit.io/badges/streamlit_badge_black_white.svg)](https://dynamic-filters-demo.streamlit.app/)\n\nCustom component to create dynamic multiselect filters in Streamlit. \nThe 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). \n\nBasic documentation is available at [https://arsentievalex.github.io/streamlit-dynamic-filters/](https://arsentievalex.github.io/streamlit-dynamic-filters/)\n\nHow to install and use the package:\n1. Install the package using [pip](https://pypi.org/project/streamlit-dynamic-filters/):\n ```pip install streamlit-dynamic-filters```\n2. Import the `DynamicFilters` class:\n ```from streamlit_dynamic_filters import DynamicFilters```\n3. Create an instance of the `DynamicFilters` class and pass the dataframe and the list of fields that will serve as filters:\n\n ```dynamic_filters = DynamicFilters(df, filters=['col1', 'col2', 'col3', 'col4'])```\n4. Display the filters in your app:\n ```dynamic_filters.display_filters()```\n5. Display the filtered dataframe:\n ```dynamic_filters.display_df()```\n\n\n#### Sample usage with sidebar filters:\n\n```\nimport streamlit as st\nimport pandas as pd\nfrom streamlit_dynamic_filters import DynamicFilters\n\ndata = {\n 'region': ['North America', 'North America', 'Europe', 'Oceania',\n 'North America', 'North America', 'Europe', 'Oceania',\n 'North America', 'North America', 'Europe', 'Oceania'],\n 'country': ['USA', 'Canada', 'UK', 'Australia',\n 'USA', 'Canada', 'UK', 'Australia',\n 'USA', 'Canada', 'UK', 'Australia'],\n 'city': ['New York', 'Toronto', 'London', 'Sydney',\n 'New York', 'Toronto', 'London', 'Sydney',\n 'New York', 'Toronto', 'London', 'Sydney'],\n 'district': ['Manhattan', 'Downtown', 'Westminster', 'CBD',\n 'Brooklyn', 'Midtown', 'Kensington', 'Circular Quay',\n 'Queens', 'Uptown', 'Camden', 'Bondi']\n}\n\ndf = pd.DataFrame(data)\n\ndynamic_filters = DynamicFilters(df, filters=['region', 'country', 'city', 'district'])\n\nwith st.sidebar:\n st.write(\"Apply filters in any order \ud83d\udc47\")\n\ndynamic_filters.display_filters(location='sidebar')\n\ndynamic_filters.display_df()\n```\n\nDemo GIF:\n<img src=\"https://i.postimg.cc/x1zDwgwh/dynamic-filters-demo-1.gif\"/> \n\n#### Sample usage with columns:\n\n```\nimport streamlit as st\nimport pandas as pd\nfrom streamlit_dynamic_filters import DynamicFilters\n\ndata = {\n 'region': ['North America', 'North America', 'Europe', 'Oceania',\n 'North America', 'North America', 'Europe', 'Oceania',\n 'North America', 'North America', 'Europe', 'Oceania'],\n 'country': ['USA', 'Canada', 'UK', 'Australia',\n 'USA', 'Canada', 'UK', 'Australia',\n 'USA', 'Canada', 'UK', 'Australia'],\n 'city': ['New York', 'Toronto', 'London', 'Sydney',\n 'New York', 'Toronto', 'London', 'Sydney',\n 'New York', 'Toronto', 'London', 'Sydney'],\n 'district': ['Manhattan', 'Downtown', 'Westminster', 'CBD',\n 'Brooklyn', 'Midtown', 'Kensington', 'Circular Quay',\n 'Queens', 'Uptown', 'Camden', 'Bondi']\n}\n\ndf = pd.DataFrame(data)\n\ndynamic_filters = DynamicFilters(df, filters=['region', 'country', 'city', 'district'])\n\nst.write(\"Apply filters in any order \ud83d\udc47\")\n\ndynamic_filters.display_filters(location='columns', num_columns=2, gap='large')\n\ndynamic_filters.display_df()\n```\n\nDemo GIF:\n<img src=\"https://i.postimg.cc/gkLTjjg6/dynamic-filters-demo-2.gif\"/> \n\n\n\n## 0.1.9 - 2nd August 2024\n### Added\n- Key for each elements in filters, so that multiple DynamicFilters can be used in one app (contribution by @vikashgraja)\n- reset_filters function (contribution by @ragchuck)\n\n\n## 0.1.6 - 27th March 2024\n### Added\n- Sorted alphabetically filter labels\n\n\n## 0.1.5 - 28th December 2023\n### Added by kzielins <Krzysztof Zielinski> kzislinsk@gmail.com\n- Hierarchical filter selectors\n- Independent filters with diffrent sessions name\n\n\n## 0.1.3 - 28th September 2023\n### Added\n- Ability to specify filter location in display_filters(). The filters can be either displayed in sidebar, main area or columns.\n- Error handling of invalid arguments in display_filters().\n\n### Changed\n- Renamed filter_except() to filter_df(). The function returns a filtered df.\n\n### Fixed\n- The StreamlitApiException that occured when selected values did not exist in the dataset.\n- Possibility to have more than one filter \n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Dynamic multiselect filters for Streamlit",
"version": "0.1.9",
"project_urls": {
"Homepage": "https://github.com/arsentievalex/streamlit-dynamic-filters"
},
"split_keywords": [
"streamlit",
" custom",
" component"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "4381bce6dd65a9abb74e5319d3da4604e735791b6044b16744164bcd9a8a9f04",
"md5": "bd74886fd9c27a53b15c11b77be59c0a",
"sha256": "0b2d6db612f35bf10e18f19de137c65b051d38ed000a6e3bfe973370b142b42d"
},
"downloads": -1,
"filename": "streamlit_dynamic_filters-0.1.9-py3-none-any.whl",
"has_sig": false,
"md5_digest": "bd74886fd9c27a53b15c11b77be59c0a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 6786,
"upload_time": "2024-08-02T11:36:33",
"upload_time_iso_8601": "2024-08-02T11:36:33.414703Z",
"url": "https://files.pythonhosted.org/packages/43/81/bce6dd65a9abb74e5319d3da4604e735791b6044b16744164bcd9a8a9f04/streamlit_dynamic_filters-0.1.9-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "a830f925349c2ba434b3c271811cbf4a4589828e34af69c0a132738650f98cdc",
"md5": "144110c9ab47a982a88b0ff226ce7130",
"sha256": "ef65029ec249a3681390711b88fcad339bb3a4ce1e13857443d4553592e23cba"
},
"downloads": -1,
"filename": "streamlit_dynamic_filters-0.1.9.tar.gz",
"has_sig": false,
"md5_digest": "144110c9ab47a982a88b0ff226ce7130",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 7628,
"upload_time": "2024-08-02T11:36:34",
"upload_time_iso_8601": "2024-08-02T11:36:34.788344Z",
"url": "https://files.pythonhosted.org/packages/a8/30/f925349c2ba434b3c271811cbf4a4589828e34af69c0a132738650f98cdc/streamlit_dynamic_filters-0.1.9.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-02 11:36:34",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "arsentievalex",
"github_project": "streamlit-dynamic-filters",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "streamlit-dynamic-filters"
}