Skip to content

pn.bind does not support the watch argument #1999

@MarcSkovMadsen

Description

@MarcSkovMadsen

I was just trying out pn.bind and I can see that it does not support setting watch=True. This limits the use cases. Then it's just easier to stick with @pn.depends as it supports all use cases.

In the below example the slider does not work.

import numpy as np
import panel as pn
import pandas as pd
import plotly.graph_objects as go

pn.extension('plotly')

data = {}
for i in range(10):
    xo = 5 * np.random.rand()
    xf = 5 + 5 * np.random.rand()
    x = np.linspace(xo, xf, int(50 + 50*np.random.rand()))
    e = np.random.rand()
    y = x**(1+e) * np.cos(x) + 4*(np.random.rand(len(x)) - 0.5)
    data[i] = {
        'x': x.tolist(),
        'y': y.tolist()
    }

nlines = pn.widgets.IntSlider(name='Number of lines', value=2, start=1, end=9)
timeseries = pn.pane.Plotly()

def get_plot(nlines):
    print("get_plot", nlines)
    fig = go.Figure()
    for i in range(nlines):
        fig.add_trace(
            go.Scatter(x=data[i]['x'], y=data[i]['y'], mode='lines', name=f'line-{i}'))
    timeseries.object = fig
get_plot(nlines.value)
pn.bind(get_plot, nlines=nlines, watch=True)

pn.Row(nlines, timeseries).servable()

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions