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

Add ability to listen to dataset linked_selection #4547

Merged
merged 2 commits into from
Sep 18, 2020
Merged

Conversation

philippjfr
Copy link
Member

@philippjfr philippjfr commented Aug 9, 2020

Linked selections are powerful and can easily be applied to HoloViews elements. However in many cases we may want to subscribe to changes in a linked selection from outside of HoloViews. This PR makes this possible by providing a new method that returns a instance parameter which will contain a reference to the current selection applied to a dataset. By combining this with the internal linked_selection cache we can make sure that if set up correctly this does not result in additional computation. As an example we can do something like this:

@pn.depends(ls.selection_param(df))
def count(selected_df):
    return f'## {len(selected_df)}/{len(df)} selected'

Here we create a callback that depends on the current selection of the df and reports the fraction of datapoints that have been selected.

@philippjfr philippjfr added the type: enhancement Minor feature or improvement to an existing feature label Aug 9, 2020
@jbednar
Copy link
Member

jbednar commented Aug 9, 2020

Looks good! This seems very convenient. Are there cases where one might want to depend on the selection itself (e.g. to apply it to some other data somehow?), rather than on the selected data as here?

@philippjfr
Copy link
Member Author

Are there cases where one might want to depend on the selection itself (e.g. to apply it to some other data somehow?), rather than on the selected data as here?

Sure but you can already do that with @param.depends(ls.param.selection_expr) but there may be a usecase for depending on the boolean mask, e.g. to compute a count that'll be more efficient than actually applying the selection and returning the data.

@jonmmease
Copy link
Collaborator

jonmmease commented Sep 25, 2020

It might not cause a problem, but the usage of cache={} function arguments throughout this PR make be a bit nervous and I was wondering if you had thought through it further than I have.

If the default empty dict value is chosen, and then modified in the function by adding to the cache, then the this default argument will be modified for all future use of the function. It might not cause a real issue, but I'd be worried about ending up with the cached values stored in default function argument values.

@philippjfr
Copy link
Member Author

If the default empty dict value is chosen, and then modified in the function by adding to the cache, then the this default argument will be modified for all future use of the function. It might not cause a real issue, but I'd be worried about ending up with the cached values stored in default function argument values.

I'd be happy with the safer thing of using a default of None and then skipping the caching (or simply using cache = {} if cache is None else cache). I think all uses of the method do pass in an explicit cache in right now though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Minor feature or improvement to an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants