Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

predefine custom filters for end users #471

Closed
fredzannarbor opened this issue Apr 27, 2021 · 4 comments
Closed

predefine custom filters for end users #471

fredzannarbor opened this issue Apr 27, 2021 · 4 comments
Labels
BackEnd Updates to the back-end enhancement New feature or request UI Updates to the front-end

Comments

@fredzannarbor
Copy link

Hi,

I am using dtale (which is great!) to enable authors to deep dive into royalty data so I want to be able to predefine a number of custom filters that are available to these not-always-tech-savvy end users when they log into the standalone dtale app. For example, one might be:

Author.str.contains($authorname) and Format=='Paperback'

How can I do this?

@aschonfeld
Copy link
Collaborator

Hmm, this is a good one. So I could certainly add a hook in the back-end where you could predefine lambda functions by column name. For example:

dtale.set_predefined_filters({
    'Author': {
        'name': 'Paperback Author',
        'func': lambda v, df: df[df['Author'].str.contains(v) & df['Format'] == 'Paperback'],
        'input': 'text',  # this could be something like 'text' or 'select'
    }
})

The tough part will be displaying these filters on the front-end. Should they be displayed in a separate filter pop-up? Or should the Column menu for the column in question (Author) display them? I'll leave that question up to you.

Thanks for the submission

@fredzannarbor
Copy link
Author

For my end users, I'd go with whatever's most prominent. A separate popup would probably be good.

I would definitely use this!

@aschonfeld aschonfeld added BackEnd Updates to the back-end enhancement New feature or request UI Updates to the front-end labels Apr 30, 2021
aschonfeld added a commit that referenced this issue Apr 30, 2021
aschonfeld added a commit that referenced this issue May 3, 2021
* #473: fixed column filters
* refactored settings (sortInfo, columnFilters, outlierFilters, predefinedFilters) to be stored in redux
* fixed issues with pinned main menu
@aschonfeld
Copy link
Collaborator

@fredzannarbor Just wanted to give you an update on this. Here's a screen recording of some data loaded using this snippet:

import pandas as pd
import dtale
import dtale.predefined_filters as predefined_filters

predefined_filters.set_filters([
    {
        "name": "A and B > 2",
        "column": "A",
        "description": "Filter A with B greater than 2",
        "handler": lambda df, val: df[(df["A"] == val) & (df["B"] > 2)],
        "input_type": "input",
    },
    {
        "name": "A and (B % 2) == 0",
        "column": "A",
        "description": "Filter A with B mod 2 equals zero (is even)",
        "handler": lambda df, val: df[(df["A"] == val) & (df["B"] % 2 == 0)],
        "input_type": "select",
    },
    {
        "name": "A in values and (B % 2) == 0",
        "column": "A",
        "description": "A is within a group of values and B mod 2 equals zero (is even)",
        "handler": lambda df, val: df[df["A"].isin(val) & (df["B"] % 2 == 0)],
        "input_type": "multiselect",
    }
])

df = pd.DataFrame(
    ([[1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12], [13, 14, 15, 16, 17, 18]]),
    columns=['A', 'B', 'C', 'D', 'E', 'F']
)
dtale.show(df)
Screen.Recording.2021-05-02.at.11.11.40.PM.mov

aschonfeld added a commit that referenced this issue May 3, 2021
* #473: fixed column filters
* refactored settings (sortInfo, columnFilters, outlierFilters, predefinedFilters) to be stored in redux
* fixed issues with pinned main menu
aschonfeld added a commit that referenced this issue May 3, 2021
* #473: fixed column filters
* refactored settings (sortInfo, columnFilters, outlierFilters, predefinedFilters) to be stored in redux
* fixed issues with pinned main menu
aschonfeld added a commit that referenced this issue May 4, 2021
* #473: fixed column filters
* refactored settings (sortInfo, columnFilters, outlierFilters, predefinedFilters) to be stored in redux
* fixed issues with pinned main menu
aschonfeld added a commit that referenced this issue May 4, 2021
* #473: fixed column filters
* refactored settings (sortInfo, columnFilters, outlierFilters, predefinedFilters) to be stored in redux
* fixed issues with pinned main menu
aschonfeld added a commit that referenced this issue May 4, 2021
* #473: fixed column filters
* refactored settings (sortInfo, columnFilters, outlierFilters, predefinedFilters) to be stored in redux
* fixed issues with pinned main menu
aschonfeld added a commit that referenced this issue May 4, 2021
* #473: fixed column filters
* refactored settings (sortInfo, columnFilters, outlierFilters, predefinedFilters) to be stored in redux
* fixed issues with pinned main menu
aschonfeld added a commit that referenced this issue May 4, 2021
* #473: fixed column filters
* refactored settings (sortInfo, columnFilters, outlierFilters, predefinedFilters) to be stored in redux
* fixed issues with pinned main menu
aschonfeld added a commit that referenced this issue May 5, 2021
* #473: fixed column filters
* refactored settings (sortInfo, columnFilters, outlierFilters, predefinedFilters) to be stored in redux
* fixed issues with pinned main menu
@aschonfeld
Copy link
Collaborator

@fredzannarbor just released v1.45.0 with this new functionality, let me know if you hit any issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BackEnd Updates to the back-end enhancement New feature or request UI Updates to the front-end
Projects
None yet
Development

No branches or pull requests

2 participants