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

pn.bind does not support the watch argument #1999

Closed
MarcSkovMadsen opened this issue Feb 23, 2021 · 6 comments · Fixed by #2000
Closed

pn.bind does not support the watch argument #1999

MarcSkovMadsen opened this issue Feb 23, 2021 · 6 comments · Fixed by #2000
Labels
type: discussion Requiring community discussion
Milestone

Comments

@MarcSkovMadsen
Copy link
Collaborator

MarcSkovMadsen commented Feb 23, 2021

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

@MarcSkovMadsen MarcSkovMadsen added the TRIAGE Default label for untriaged issues label Feb 23, 2021
@philippjfr philippjfr added type: discussion Requiring community discussion and removed TRIAGE Default label for untriaged issues labels Feb 23, 2021
@jbednar
Copy link
Member

jbednar commented Feb 23, 2021

Here I assume you meant pn.bind(get_plot, nlines=nlines, watch=True)? That's an interesting suggestion, addressing something @jlstevens was worried about, i.e. that pn.bind only generates updates when the output of it is embedded in a Panel layout. I guess with watch=True that semantics would change, and it would be registered for updates regardless of whether it's in a layout?

@MarcSkovMadsen MarcSkovMadsen removed the type: discussion Requiring community discussion label Feb 23, 2021
@MarcSkovMadsen
Copy link
Collaborator Author

Exactly

@MarcSkovMadsen MarcSkovMadsen added the type: discussion Requiring community discussion label Feb 23, 2021
@jlstevens
Copy link
Contributor

This was indeed something that bothered me about bind.

Like Marc, I would like the option to watch it (can be off by default) but the problem I have with watch=True is that it means there is a namespace clash with any potential parameter called watch. I guess an actual watch parameter would take precedence (in which case you wouldn't be able to watch it?!).

@jbednar
Copy link
Member

jbednar commented Feb 23, 2021

I think bind's own watch argument should take precedence, because if it ever clashes, you can always just wrap whatever function you want in a lambda that renames the original function's watch argument. Seems cleaner for bind to strip off things it knows about, consume them, and pass all the rest down to the function, without having to inspect the underlying function for clashes.

@MarcSkovMadsen
Copy link
Collaborator Author

Agree that watch is special and reserved for Param/ Panel.

This PR adds the support #2000

@jlstevens
Copy link
Contributor

jlstevens commented Feb 23, 2021

I suppose a lambda would be an annoying (but valid) solution and I agree that it is probably best to consume watch as an instruction to bind first. I generally dislike these kinds of namespace clashes but in this case I value being able to watch things more.

I would mention @MarcSkovMadsen that bind is being added to param right now and it is important that things match up before any releases happen: holoviz/param#460

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: discussion Requiring community discussion
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants