Data Set Filters

We provide a way to filter data sets dynamically, to affect all the charts that use a specific data set. The filter is a component in itself so it will be using an order, and it will need to be passed an exiting shared data set by name.

The function to use is the following (using s as the Shimoku client):

s.plt.filter(
    order: int,                   # Order in the view
    data: str,                    # The name of the shared data set
    field: str,                   # The field from the data set to be filtered
    multi_select: bool = False,   # Wether to use the multi select for categoricals
    cols_size: int = 4,           # The number columns that will occupy the filter
    rows_size: int = 1,           # The number of rows that will occupy the filter
    padding: Optional[str] = None # The padding that will be applie to the filter
 )

The filter works with 4 types of inputs, for different types of values, this will be inferred by the field to be filtered. The types are:

For an example we will be using this data set:

data_to_filter = [
    {'date': dt.date(2021, 1, 1), 'x': 5, 'y': 5, 'filtA': 'A', 'filtB': 'Z', 'name': 'Ana'},
    {'date': dt.date(2021, 1, 2), 'x': 6, 'y': 5, 'filtA': 'B', 'filtB': 'Z', 'name': 'Laura'},
    {'date': dt.date(2021, 1, 3), 'x': 4, 'y': 5, 'filtA': 'A', 'filtB': 'W', 'name': 'Audrey'},
    {'date': dt.date(2021, 1, 4), 'x': 7, 'y': 5, 'filtA': 'B', 'filtB': 'W', 'name': 'Jose'},
    {'date': dt.date(2021, 1, 5), 'x': 3, 'y': 5, 'filtA': 'A', 'filtB': 'Z', 'name': 'Jorge'},
]

and we will use three linked charts joined to this data set:

s.reuse_data_sets()  # For later executions

s.plt.set_shared_data(dfs={'filters data': pd.DataFrame(data_to_filter)})

s.plt.bar(data='filters data', x='date', y='x', order=0, cols_size=6)
s.plt.doughnut(data='filters data', names='date', values='x', order=1, cols_size=6)
s.plt.stacked_area(data='filters data', x='date', y=['x', 'y'], order=2)

To use the numeric filter we will specify the x field as it has more variation than the y field:

s.plt.filter(order=3, data='filters data', field='x')

The possible operations are the following:

If we set the operation to > and the value to 4 we get:

It is not recommended to use more than one filter on a single data set, only one filter can have effect on a data set at a time, and this can be confusing for the user.

Last updated