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

Adds the watch argument to pn.bind #2000

Merged
merged 3 commits into from
Feb 25, 2021
Merged

Adds the watch argument to pn.bind #2000

merged 3 commits into from
Feb 25, 2021

Conversation

MarcSkovMadsen
Copy link
Collaborator

Fixes #1999

@MarcSkovMadsen
Copy link
Collaborator Author

MarcSkovMadsen commented Feb 23, 2021

Manual Test Is below

I've tried the test without watch and with watch=False and it works as I would expect.

pn_bind_works

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()

@codecov
Copy link

codecov bot commented Feb 23, 2021

Codecov Report

Merging #2000 (3c5bf32) into master (3dc12d2) will decrease coverage by 0.15%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2000      +/-   ##
==========================================
- Coverage   84.66%   84.51%   -0.16%     
==========================================
  Files         163      175      +12     
  Lines       19729    20415     +686     
==========================================
+ Hits        16704    17253     +549     
- Misses       3025     3162     +137     
Impacted Files Coverage Δ
panel/depends.py 83.33% <100.00%> (ø)
panel/compiler.py 7.52% <0.00%> (-2.48%) ⬇️
panel/param.py 89.07% <0.00%> (-2.43%) ⬇️
panel/io/reload.py 65.88% <0.00%> (-2.36%) ⬇️
panel/widgets/button.py 81.48% <0.00%> (-2.31%) ⬇️
panel/io/model.py 60.97% <0.00%> (-0.93%) ⬇️
panel/pane/vtk/synchronizable_serializer.py 79.93% <0.00%> (-0.91%) ⬇️
panel/pane/holoviews.py 79.64% <0.00%> (-0.57%) ⬇️
panel/widgets/input.py 95.83% <0.00%> (-0.04%) ⬇️
panel/pane/vtk/vtk.py 96.39% <0.00%> (-0.03%) ⬇️
... and 42 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3dc12d2...3c5bf32. Read the comment docs.

panel/depends.py Outdated Show resolved Hide resolved
Copy link
Member

@philippjfr philippjfr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@MarcSkovMadsen
Copy link
Collaborator Author

Thanks. Great to get it in. Now I will start to learn to use it.

I think that for many users explicitly declaring widgets and binding them to a function is easier to understand than parameterized classes, Param and annotations.

Let me know if there is anything I should do.

@philippjfr philippjfr merged commit de452a5 into master Feb 25, 2021
@philippjfr philippjfr deleted the bind-with-watch branch February 25, 2021 20:40
Comment on lines +86 to +87
Whether the function will be automatically evaluated when one
of the parameter dependencies change.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Whether the function will be automatically evaluated when one
of the parameter dependencies change.
Whether to evaluate the function automatically whenever one of the
bound parameters changes.

Comment on lines +121 to +122
Whether the function will be automatically evaluated when one
of the parameter dependencies change.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Whether the function will be automatically evaluated when one
of the parameter dependencies change.
Whether to evaluate the function automatically whenever one of the
bound parameters changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pn.bind does not support the watch argument
3 participants