New Component: Dynamic multi-select filters

Hi @saasyp at the moment, the component supports only st.dataframe, but you could probably do something like this:

dynamic_filters = DynamicFilters(df, filters=['col1', 'col2', 'col3'], filters_name='my_filters')
dynamic_filters.display_filters(location='sidebar')

new_df = dynamic_filters.filter_df()
st.data_editor(new_df)
2 Likes

Thanks. That works great!

2 Likes

I’m sorry for the silly question! Your suggestion is what I was looking for, thanks for your help!

2 Likes

Hi Oleksandr,

I am using DynamicFilters. I am getting “Row index out of range” error in Devtools. I copied the DynamicFilters code into a separate file and ran it. I still get the errors.

The error messages appear when I start filtering using the multiselect boxes.

As I select additional filters, I get more errors. These errors are only seen in Devtools. The app works fine. There are 7089 rows in the dataframe.

Row index out of range: 7089 (listed 9 times)
Row index out of range: 2 (listed 9 times)
Row index out of range: 3 (listed 9 times)
Row index out of range: 4 (listed 9 times)

Row index out of range: 4136 (listed 9 times)

Isolated code:
import streamlit as st
import pandas as pd
import altair as alt
from streamlit_dynamic_filters import DynamicFilters
import warnings
warnings.filterwarnings(‘ignore’)

@st.cache_data
def load_data():
data = pd.read_csv(“US_Breweries.csv”)
data[‘postal_code’] = data[‘postal_code’].str.slice(0,5)
data = data[[‘name’,‘brewery_type’,‘address_1’,‘city’,‘state’,‘postal_code’,‘phone’,‘website_url’]].copy()
return data

df = load_data()
selected_breweries = df.copy()

st.write(“Apply filters:”)

dynamic_filters = DynamicFilters(selected_breweries, filters=[‘state’, ‘city’, ‘brewery_type’, ‘postal_code’, ‘name’], filters_name = ‘filters1’)

dynamic_filters.display_filters(location=‘columns’, num_columns=2, gap=‘large’)

selected_breweries = dynamic_filters.filter_df()

st.write(“”)
st.write(“”)

with st.expander(“Data Preview”):
st.write(“Hover over column name to display icons on the right for download, search, fullscreen”)
st.write(“Click columns names to sort”)
dynamic_filters.display_df()

st.write(“”)

Thanks

1 Like

HI Oleksandr_Aresentiev

I’ve been effectively utilizing the Dynamic Filter package. However, I encountered limitations in adjusting positions and applying names to the filters(not dataframe column name). Consequently, I’ve developed a solution to these issues. I’m curious about the best practices for distributing this enhancement. Any guidance or suggestions would be greatly appreciated.

1 Like

Hi dongbang_ban,

Have you noticed any Row out of index errors when you look at devtools after using the DynamicFilters?

1 Like

Hii, @Oleksandr_Arsentiev, can this dynamic filters applied to multiple dfs?

1 Like

Hi @Oleksandr_Arsentiev I’ve been using the dynamic filters lib for a while and it’s amazing! I just have one question: is it possible to use the same filters in multiple pages, where I can change them in one page and it applies to all pages with the filter?

1 Like