Skip to content

Update docs to use the bound function as a reference #6271

Description

@ahuang11

Often, coming from the widget.param.watch() historical past, I would use watch=True in pn.bind:

import panel as pn
pn.extension()

def update_value(select_value, slider_value):
    value = select_value * slider_value
    text.value = value

slider = pn.widgets.IntSlider(value=5, start=1, end=10)
select = pn.widgets.Select(value="⭐", options=["⭐", "🐘"])
text = pn.widgets.StaticText()
pn.bind(update_value, select, slider, watch=True)

pn.Row(slider, select, text).show()

Others mentioned that was an anti-pattern, and shared that I can do this instead:

import panel as pn
pn.extension()

def update_value(select_value, slider_value):
    value = select_value * slider_value
    return value

slider = pn.widgets.IntSlider(value=5, start=1, end=10)
select = pn.widgets.Select(value="⭐", options=["⭐", "🐘"])
text = pn.widgets.StaticText()
text.value = pn.bind(update_value, select, slider)

pn.Row(slider, select, text).show()

To ideally:

import panel as pn
pn.extension()

def update_value(select_value, slider_value):
    value = select_value * slider_value
    return value

slider = pn.widgets.IntSlider(value=5, start=1, end=10)
select = pn.widgets.Select(value="⭐", options=["⭐", "🐘"])
text = pn.widgets.StaticText(value=pn.bind(update_value, select, slider))

pn.Row(slider, select, text).show()

I think this should be documented in the docs
https://panel.holoviz.org/how_to/interactivity/bind_component.html

The benefit of doing this is not recreating the object.

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGood for newcomerstype: docsRelated to the Panel documentation and examples

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions