SolaraS
Solara2y ago
Cyrus

cross-filtering ipyaggrid element in Solara

Hi, is there a way to cross filter a ipyaggrid element in solara based on other Solara components (Sliders, Select, etc)? I tried creating a custom solara.CrossFilterGrid similar to solara.CrossFilterDataFrame. I could not get it to work but maybe I am missing something. Here is my reproducible example

import ipyaggrid
import plotly.express as px
import solara

df = px.data.iris()
column_defs = [
    {'headerName': 'Sepal Length', 'field': 'sepal_length'},
    {'headerName': 'Species', 'field': 'species'},
]
grid_options = {'columnDefs': column_defs}


@solara.component
def CrossFilterGrid(df, grid_options):
    dff = df
    filter, set_filter = solara.use_cross_filter(id(df), 'grid')
    if filter is not None:
        dff = df[filter]
    return ipyaggrid.Grid.element(grid_data=dff, grid_options=grid_options)


@solara.component
def Page():
    solara.provide_cross_filter()
    with solara.Columns([1,1]):
        solara.CrossFilterDataFrame(df)  # <--- This works
        CrossFilterGrid(df, grid_options)  # <--- This does not work
        with solara.Column():
            solara.CrossFilterSelect(df, 'species')
            solara.CrossFilterSlider(df, 'sepal_length', mode='>')

I am actually also interested in doing the reverse: have Solara charts react to when I filter my ipyaggrid by clicking on the grid directly (for example, when clicking on checkboxes for each row). This might be harder to do? Thanks!
Was this page helpful?