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

Can't mix pn.bind with streams in DynamicMaps anymore #6008

Closed
TheoMathurin opened this issue Dec 5, 2023 · 5 comments · Fixed by #6009
Closed

Can't mix pn.bind with streams in DynamicMaps anymore #6008

TheoMathurin opened this issue Dec 5, 2023 · 5 comments · Fixed by #6009

Comments

@TheoMathurin
Copy link
Contributor

HoloViews 1.18.1
Param 2.0.1
Panel 1.3.4

Description of expected behavior and the observed behavior

I used to be able to wrap a pn.bind within a DynamicMap and add a streams argument like the following:
dmap = hv.DynamicMap(pn.bind(function, arg=some_widget), streams=[some_stream])

This is useful for plots driven both by widgets and streams.

But now this causes an error where expected inputs are missing, maybe related to the new Param version.

MRE

In a panel server

import holoviews as hv
import panel as pn

pn.extension()


def make_plot(z, x_range, y_range):
    print(z)
    print(x_range, y_range)
    return hv.Curve([1, 2, 3, 4])


slider = pn.widgets.IntSlider(name='Slider', start=0, end=10)
range_xy = hv.streams.RangeXY()
dmap = hv.DynamicMap(pn.bind(make_plot, z=slider), streams=[range_xy])

pn.Column(slider, dmap).servable()

Stack traceback and/or browser JavaScript console output

return eval_fn()(*combined_args, **combined_kwargs) Traceback (most recent call last):
  File "/home/mathurin/miniconda3/envs/hv/lib/python3.12/site-packages/bokeh/application/handlers/code_runner.py", line 229, in run
    exec(self._code, module.__dict__)
  File "/home/mathurin/PycharmProjects/test/toast.py", line 18, in <module>
    pn.Column(slider, dmap).servable()
  File "/home/mathurin/miniconda3/envs/hv/lib/python3.12/site-packages/panel/viewable.py", line 394, in servable
    self.server_doc(title=title, location=location) # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mathurin/miniconda3/envs/hv/lib/python3.12/site-packages/panel/viewable.py", line 1023, in server_doc
    model = self.get_root(doc)
            ^^^^^^^^^^^^^^^^^^
  File "/home/mathurin/miniconda3/envs/hv/lib/python3.12/site-packages/panel/layout/base.py", line 309, in get_root
    root = super().get_root(doc, comm, preprocess)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mathurin/miniconda3/envs/hv/lib/python3.12/site-packages/panel/viewable.py", line 670, in get_root
    root = self._get_model(doc, comm=comm)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mathurin/miniconda3/envs/hv/lib/python3.12/site-packages/panel/layout/base.py", line 177, in _get_model
    objects, _ = self._get_objects(model, [], doc, root, comm)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mathurin/miniconda3/envs/hv/lib/python3.12/site-packages/panel/layout/base.py", line 159, in _get_objects
    child = pane._get_model(doc, root, model, comm)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mathurin/miniconda3/envs/hv/lib/python3.12/site-packages/panel/pane/holoviews.py", line 414, in _get_model
    plot = self._render(doc, comm, root)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mathurin/miniconda3/envs/hv/lib/python3.12/site-packages/panel/pane/holoviews.py", line 509, in _render
    return renderer.get_plot(self.object, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mathurin/miniconda3/envs/hv/lib/python3.12/site-packages/holoviews/plotting/bokeh/renderer.py", line 68, in get_plot
    plot = super().get_plot(obj, doc, renderer, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mathurin/miniconda3/envs/hv/lib/python3.12/site-packages/holoviews/plotting/renderer.py", line 217, in get_plot
    initialize_dynamic(obj)
  File "/home/mathurin/miniconda3/envs/hv/lib/python3.12/site-packages/holoviews/plotting/util.py", line 270, in initialize_dynamic
    dmap[dmap._initial_key()]
    ~~~~^^^^^^^^^^^^^^^^^^^^^
  File "/home/mathurin/miniconda3/envs/hv/lib/python3.12/site-packages/holoviews/core/spaces.py", line 1216, in __getitem__
    val = self._execute_callback(*tuple_key)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mathurin/miniconda3/envs/hv/lib/python3.12/site-packages/holoviews/core/spaces.py", line 983, in _execute_callback
    retval = self.callback(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mathurin/miniconda3/envs/hv/lib/python3.12/site-packages/holoviews/core/spaces.py", line 550, in __call__
    return self.callable.rx.value
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mathurin/miniconda3/envs/hv/lib/python3.12/site-packages/param/reactive.py", line 253, in value
    return self._reactive()
           ^^^^^^^^^^^^^^^^
  File "/home/mathurin/miniconda3/envs/hv/lib/python3.12/site-packages/param/depends.py", line 41, in _depends
    return func(*args, **kw)
           ^^^^^^^^^^^^^^^^^
  File "/home/mathurin/miniconda3/envs/hv/lib/python3.12/site-packages/param/reactive.py", line 431, in wrapped
    return eval_fn()(*combined_args, **combined_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: make_plot() missing 2 required positional arguments: 'x_range' and 'y_range'
@hoxbro
Copy link
Member

hoxbro commented Dec 5, 2023

Likely a consequence of the param 2.0 upgrade. As a workaround this should work:

import holoviews as hv
import panel as pn

pn.extension()


def make_plot(value, x_range, y_range):
    print(value)
    print(x_range, y_range)
    return hv.Curve([1, 2, 3, 4])


slider = pn.widgets.IntSlider(name='Slider', start=0, end=10)
range_xy = hv.streams.RangeXY()
dmap = hv.DynamicMap(make_plot, streams=[slider.param.value, range_xy])

pn.Column(slider, dmap).servable()

@TheoMathurin
Copy link
Contributor Author

Thank you @hoxbro for your reply and the PR.

I had found this workaround but unfortunately it is limited to one argument called "value". In my real-world app the DynamicMap is driven by the .param.value of more than one widget so this cannot work.

@hoxbro
Copy link
Member

hoxbro commented Dec 5, 2023

Can you test if the fix in the PR will work for you?

@TheoMathurin
Copy link
Contributor Author

It does!

Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants