Skip to content

Support panel widget.link(stream, selection="index") #7801

Description

@ahuang11
import holoviews as hv
import numpy as np
import pandas as pd
import panel as pn
import param

hv.extension("bokeh")
pn.extension("tabulator")

grid_size = 3
grid_bounds = (-0.5, grid_size - 0.5)
grid_x, grid_y = np.meshgrid(range(grid_size), range(grid_size))
grid_data = pd.DataFrame(
    {
        "x": grid_x.flatten(),
        "y": grid_y.flatten(),
        "value": np.random.uniform(size=grid_size * grid_size),
    }
)

def selection1d_to_tabulator(index):
    tabulator.selection = index

def tabulator_to_selection1d(selection):
    selection_1d.event(index=selection)

def create_points(index):
    return hv.Points(grid_data).opts(selected=index, size=25)

selection_1d = hv.streams.Selection1D()
tabulator = pn.widgets.Tabulator(grid_data, selectable=True, disabled=True)
dmap_heatmap = hv.DynamicMap(create_points, streams=[selection_1d]).opts(tools=["tap"])
pn.bind(selection1d_to_tabulator, selection_1d.param.index, watch=True)
pn.bind(tabulator_to_selection1d, tabulator.param.selection, watch=True)
pn.Column(tabulator, dmap_heatmap).show()

I want to simplify the two bind with a link call.

However, tabulator.link(selection_1d, selection="index", bidirectional=True) does not trigger the event.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: enhancementMinor feature or improvement to an existing feature

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions