Skip to main content

Dynamic multiselect filters for Streamlit

Project description

Open Demo 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).

Sample usage:

import streamlit as st
from streamlit_dynamic_filters import DynamicFilters

data = {
    'Region': ['North America', 'North America', 'North America', 'Europe', 'Europe', 'Asia', 'Asia'],
    'Country': ['USA', 'USA', 'Canada', 'Germany', 'France', 'Japan', 'China'],
    'City': ['New York', 'Los Angeles', 'Toronto', 'Berlin', 'Paris', 'Tokyo', 'Beijing']
    }

df = pd.DataFrame(data)

dynamic_filters = DynamicFilters(df, filters=['Region', 'Country', 'City'])

with st.sidebar:
    dynamic_filters.display_filters()

dynamic_filters.display_df()

Demo GIF:

0.1.3 - 28th September

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.

Deprecated

Removed

Fixed

  • The StreamlitApiException that occured when selected values did not exist in the dataset.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

streamlit_dynamic_filters-0.1.3.tar.gz (4.1 kB view hashes)

Uploaded Source

Built Distribution

streamlit_dynamic_filters-0.1.3-py3-none-any.whl (4.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page