# What's the best practice for linking up HoloViews streams with \`Parameterized\`

**URL:** <https://discourse.holoviz.org/t/whats-the-best-practice-for-linking-up-holoviews-streams-with-parameterized/8215>\
**Category:** Panel\
**Tags:** panel\
**Created:** [September 19, 2024, 7:58pm UTC](https://discourse.holoviz.org/t/whats-the-best-practice-for-linking-up-holoviews-streams-with-parameterized/8215 "2024-09-19T19:58:24Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ahuang11](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/ahuang11/32/4947_2.png) [@ahuang11](https://discourse.holoviz.org/u/ahuang11)\
**Post date:** [September 19, 2024, 7:58pm UTC](https://discourse.holoviz.org/t/whats-the-best-practice-for-linking-up-holoviews-streams-with-parameterized/8215/1 "2024-09-19T19:58:24Z")

</div>

For widgets, there’s `pn.Param` and `from_param`.

What’s the equivalent for HoloViews streams?

Below is a single direction; tap updates the spinner widgets from param, but not the other way around. Is there an easy to link it up bidirectionally?

```python
import param
import holoviews as hv
import panel as pn

pn.extension()

class TapTest(pn.custom.PyComponent):

    x = param.Number(default=0)
    y = param.Number(default=0)

    def __init__ (self, **params):
        super(). __init__ (**params)

        self._tap = hv.streams.Tap()
        hv_pane = pn.pane.HoloViews()
        hv_pane.object = hv.DynamicMap(self.plot, streams=[self._tap])

        # is there something better?
        pn.bind(self._update_x_y, self._tap.param.x, self._tap.param.y, watch=True)
        self._layout = pn.Column(hv_pane, self.param.x, self.param.y)

    def plot(self, x, y):
        return hv.Points([(x, y)]).opts(tools=['tap'])

    def _update_x_y(self, x, y):
        self.x = x
        self.y = y

    def __panel__ (self):
        return self._layout

TapTest()

```

---

<div class="post-metadata">

**Author:** ![krkl](https://discourse.holoviz.org/letter_avatar_proxy/v4/letter/k/9fc348/32.png) [@krkl](https://discourse.holoviz.org/u/krkl)\
**Post date:** [September 22, 2024, 6:35am UTC](https://discourse.holoviz.org/t/whats-the-best-practice-for-linking-up-holoviews-streams-with-parameterized/8215/2 "2024-09-22T06:35:15Z")

</div>

Hi,

I think it should work with the addition of the tap.event() mehtod and directly plotting the self.x and self.y. Here the update x,y is directly within the plot function. It should also work if you keep it as in your example. Maybe you check how often these update functions are getting called because they might loop.

Best regards

```auto
import param
import holoviews as hv
import panel as pn
pn.extension()

class TapTest(pn.custom.PyComponent):
    x = param.Number(default=0)
    y = param.Number(default=0)

    def __init__ (self, **params):
        super(). __init__ (**params)

        self._tap = hv.streams.Tap()
        hv_pane = pn.pane.HoloViews()
        hv_pane.object = hv.DynamicMap(self.plot, streams=[self._tap])
        
        pn.bind(self.update_tap, self.param.x, self.param.y, watch=True)
        
        self._layout = pn.Column(hv_pane, self.param.x, self.param.y)

    def update_tap(self, x, y):
        self._tap.event(x=x, y=y)

    def plot(self, x, y):
        if x and y:
            self.param.update(x=x, y=y)
        return hv.Points([(self.x, self.y)]).opts(tools=['tap'])

    def __panel__ (self):
        return self._layout

pn.serve(TapTest())

```

---

<div class="post-metadata">

**Author:** ![ahuang11](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/ahuang11/32/4947_2.png) [@ahuang11](https://discourse.holoviz.org/u/ahuang11)\
**Post date:** [September 23, 2024, 3:59pm UTC](https://discourse.holoviz.org/t/whats-the-best-practice-for-linking-up-holoviews-streams-with-parameterized/8215/3 "2024-09-23T15:59:04Z")

</div>

Thank you! That does seem to make it bidirectional, but it’s a lot of work compared to `from_param`. I wonder if there’s a simpler solution.

---

<div class="post-metadata">

**Author:** ![ahuang11](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/ahuang11/32/4947_2.png) [@ahuang11](https://discourse.holoviz.org/u/ahuang11)\
**Post date:** [September 23, 2024, 5:13pm UTC](https://discourse.holoviz.org/t/whats-the-best-practice-for-linking-up-holoviews-streams-with-parameterized/8215/4 "2024-09-23T17:13:42Z")

</div>

This would be nice if it worked:

```python
import param
import holoviews as hv
import panel as pn
pn.extension()

class TapTest(pn.custom.PyComponent):
    x = param.Number(default=0)
    y = param.Number(default=0)

    def __init__ (self, **params):
        super(). __init__ (**params)

        self._tap = hv.streams.Tap()

        hv_pane = pn.pane.HoloViews()
        hv_pane.object = hv.DynamicMap(self.plot, streams=[self._tap])

        x_spinner = pn.widgets.FloatSlider.from_param(self.param.x)
        y_spinner = pn.widgets.FloatSlider.from_param(self.param.y)
        x_spinner.link(self._tap, value='x', bidirectional=True)
        y_spinner.link(self._tap, value='y', bidirectional=True)
        self._layout = pn.Column(hv_pane, x_spinner, y_spinner)

    def plot(self, x, y):
        return hv.Points([(x, y)]).opts(tools=['tap'])

    def __panel__ (self):
        return self._layout

pn.serve(TapTest())

```

> <https://github.com/holoviz/holoviews/issues/6384>
>
> For widgets, there’s pn.Param and from\_param.
> 
> What’s the equivalent for HoloV…iews streams?
> 
> https://discourse.holoviz.org/t/whats-the-best-practice-for-linking-up-holoviews-streams-with-parameterized/8215/3
> 
> I thought the following would work, but I get \`TypeError: Constant parameter 'x' cannot be modified\`
> 
> Can we remove the \`constant=True\`, or create a dedicated method like \`from\_param\` or \`from\_params\`?
> 
> \<img width="330" alt="image" src="https://github.com/user-attachments/assets/7e1bad56-df3a-4a91-bcc2-7983b120fa53"\>
> 
> 
> \`\`\`python
> import param
> import holoviews as hv
> import panel as pn
> pn.extension()
> 
> class TapTest(pn.custom.PyComponent):
> x = param.Number(default=0)
> y = param.Number(default=0)
> 
> def \_\_init\_\_(self, \*\*params):
> super().\_\_init\_\_(\*\*params)
> 
> self.\_tap = hv.streams.Tap()
> 
> hv\_pane = pn.pane.HoloViews()
> hv\_pane.object = hv.DynamicMap(self.plot, streams=\[self.\_tap\])
> 
> x\_spinner = pn.widgets.FloatSlider.from\_param(self.param.x)
> y\_spinner = pn.widgets.FloatSlider.from\_param(self.param.y)
> x\_spinner.link(self.\_tap, value='x', bidirectional=True)
> y\_spinner.link(self.\_tap, value='y', bidirectional=True)
> self.\_layout = pn.Column(hv\_pane, x\_spinner, y\_spinner)
> 
> 
> def plot(self, x, y):
> return hv.Points(\[(x, y)\]).opts(tools=\['tap'\])
> 
> def \_\_panel\_\_(self):
> return self.\_layout
> 
> pn.serve(TapTest())
> \`\`\`
> 
> The workaround is a bit more code
> 
> \`\`\`python
> import param
> import holoviews as hv
> import panel as pn
> pn.extension()
> 
> class TapTest(pn.custom.PyComponent):
> x = param.Number(default=0)
> y = param.Number(default=0)
> 
> def \_\_init\_\_(self, \*\*params):
> super().\_\_init\_\_(\*\*params)
> 
> self.\_tap = hv.streams.Tap()
> hv\_pane = pn.pane.HoloViews()
> hv\_pane.object = hv.DynamicMap(self.plot, streams=\[self.\_tap\])
>         
> pn.bind(self.update\_tap, self.param.x, self.param.y, watch=True)
>         
> self.\_layout = pn.Column(hv\_pane, self.param.x, self.param.y)
> 
> def update\_tap(self, x, y):
> self.\_tap.event(x=x, y=y)
> 
> def plot(self, x, y):
> if x and y:
> self.param.update(x=x, y=y)
> return hv.Points(\[(self.x, self.y)\]).opts(tools=\['tap'\])
> 
> def \_\_panel\_\_(self):
> return self.\_layout
> 
> pn.serve(TapTest())
> \`\`\`

---

<div class="post-metadata">

**Author:** ![krkl](https://discourse.holoviz.org/letter_avatar_proxy/v4/letter/k/9fc348/32.png) [@krkl](https://discourse.holoviz.org/u/krkl)\
**Post date:** [September 26, 2024, 7:22pm UTC](https://discourse.holoviz.org/t/whats-the-best-practice-for-linking-up-holoviews-streams-with-parameterized/8215/5 "2024-09-26T19:22:54Z")

</div>

Hi,

thanks for writing an issue. As I am quite interested in working with biderectional tools, I tried few more things and came up with this. I don’t know exactly whats going on with the added callback and how it is connected to the the tab tool within the plot and I have also no idea why it does not create an infinite loop.  
However, also not optimal.

```auto
import param
import panel as pn
import holoviews as hv
from holoviews.streams import Tap, Stream
from holoviews.plotting.bokeh.callbacks import TapCallback
from numbers import Number

pn.extension()
class TapBi(Tap):
    """
    The x/y-position of a tap or click in data coordinates.
    """
    x_sel = param.ClassSelector(class_=Number, default=None,)
    y_sel = param.ClassSelector(class_=Number, default=None,)
    def transform(self):
        return {'x_sel': self.x,
                'y_sel': self.y}

Stream._callbacks['bokeh'].update({TapBi: TapCallback})

class TapTest(pn.custom.PyComponent):
    tap = TapBi()
    def __init__ (self, **params):
        super(). __init__ (**params,)
        hv_pane = pn.pane.HoloViews()
        hv_pane.object = hv.DynamicMap(self.plot, streams=[self.tap])
        self._layout = pn.Column(hv_pane, self.tap.param.x_sel, self.tap.param.y_sel)

    @param.depends('tap.x_sel', 'tap.y_sel', watch=True)
    def trigger_tap(self, **kwargs):
        print("update")
        self.tap.event(x=self.tap.x_sel, y=self.tap.y_sel)
    def plot(self,x,y, **kwargs): 
        return hv.Points([(x, y)]).opts(tools=['tap'])

    def __panel__ (self):
        return self._layout

pn.serve(TapTest())

```

---

<div class="post-metadata">

**Author:** ![ahuang11](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/ahuang11/32/4947_2.png) [@ahuang11](https://discourse.holoviz.org/u/ahuang11)\
**Post date:** [September 26, 2024, 8:16pm UTC](https://discourse.holoviz.org/t/whats-the-best-practice-for-linking-up-holoviews-streams-with-parameterized/8215/6 "2024-09-26T20:16:04Z")

</div>

Planning on implementing this feature soon!

---

<div class="post-metadata">

**Author:** ![ahuang11](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/ahuang11/32/4947_2.png) [@ahuang11](https://discourse.holoviz.org/u/ahuang11)\
**Post date:** [March 22, 2025, 1:56am UTC](https://discourse.holoviz.org/t/whats-the-best-practice-for-linking-up-holoviews-streams-with-parameterized/8215/7 "2025-03-22T01:56:30Z")

</div>

WIP: [feat: Implement stream.from\_param by ahuang11 · Pull Request #6396 · holoviz/holoviews · GitHub](https://github.com/holoviz/holoviews/pull/6396)

Otherwise

> [@Bidirectionally sync HoloViews with Panel](https://discourse.holoviz.org/t/bidirectionally-sync-holoviews-with-panel/8655):
>
> [points] [heatmap] Points: 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): t…
