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

Linked Selections Generalization #6430

Open
philippjfr opened this issue Oct 31, 2024 · 0 comments
Open

Linked Selections Generalization #6430

philippjfr opened this issue Oct 31, 2024 · 0 comments
Labels
type: discussion type: enhancement Minor feature or improvement to an existing feature

Comments

@philippjfr
Copy link
Member

The link_selections functionality is one of the most powerful features in HoloViews and while it is tightly coupled with HoloViews internals, the basic concept is actually quite general. Specifically the core of it involves taking selections and applying them to different datasets, something that could easily be leveraged by other libraries, such as Panel, to allow selections on plots and other visual components to be synced.

The main things that are missing to make this easier are a few APIs to set this up manually:

  • update_selection(name: str, dimension: str | Dimension, selection: tuple[number, number] | list[any] | constant): An API to manually add a selection along a particular dimension. By giving each selection a unique name they can be updated easily.
  • compute_mask(dataframe: DataFrameLike | Dataset): Returns a set of indices of the selected rows

These two APIs would be sufficient for components in Panel and other libraries to use link_selections more effectively. Beyond that we could consider implementing a plugin API where external components can register handlers that would make it possible to call link_selections on objects of a particular type, e.g. making this possible:

table = pn.widgets.Tabulator(df)

ls = hv.link_selections.instance()

ls(table)

Internally this would effectively do the following:

def setup_tabulator(ls, table):

    def sync_selection(e):
        ls.update_selection(e.obj.name, '__index__', e.new)

    table.param.watch(sync_selection, 'selection')

    def update_selection(e):
        table.selection = ls.compute_mask(table.value)

    ls.param.watch(update_selection, 'selection_expr')

hv.link_selections.register(pn.widgets.Tabulator, setup_tabulator)
@philippjfr philippjfr added TRIAGE Needs triaging type: discussion type: enhancement Minor feature or improvement to an existing feature and removed TRIAGE Needs triaging labels Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: discussion type: enhancement Minor feature or improvement to an existing feature
Projects
None yet
Development

No branches or pull requests

1 participant