arsentievalex / streamlit-dynamic-filters

Custom component with dynamic multiselect filters for Streamlit
MIT License
68 stars 12 forks source link

Using this with a visualisation #1

Closed rida2689 closed 1 year ago

rida2689 commented 1 year ago

I am trying to build an app with a network visualisation library (PyVis) and would love to use this package to dynamically filter the elements of the network. However, it seems that it is only possible to use the output of the filter with displaying a dataframe. Can I clarify that is the case?

rida2689 commented 1 year ago

Just figured it out! You can do something like:

dynamic_filters = DynamicFilters(df, filters=['Filter1', 'Filter2', 'Filter3'])

with st.sidebar:
    dynamic_filters.display_filters()

filtered_df = dynamic_filters.filter_except()

You can then use the filtered_df to make your visualisation. Thank you!

arsentievalex commented 1 year ago

Hi @rida2689 thanks for opening the issue and glad you found a solution so quickly! I just updated the package version to 0.1.3 and added a few new features.

The filter_except() is now renamed to filter_df() and you can assign it to your variable exactly as you did: filtered_df = dynamic_filters.filter_df()

In addition, you can specify the location of the filters, either sidebar, columns or main area: dynamic_filters.display_filters(location='sidebar') Or dynamic_filters.display_filters(location='columns', num_columns=2, gap='large')