question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Supporting panel widgets directly as streams

See original GitHub issue

HoloViews supports turning parameters directly into streams such that DynamicMaps update when parameter values change (the parameters are promoted to a Params stream internally). Panel widgets are also based on param and I was hoping to use this support to drive a DynamicMap with panel widgets. Unfortunately, as soon as you try to use more than one panel widget this way, you encounter name clashes as all widget value parameters have the same name (namely widget.param.value).

Given that parameters can be used as streams, I would like to use param widgets directly as well, using the widget name (or some sort of identifier label which I think would be useful in Panel more generally e.g to select a specific widget out of a bank of widgets by name) as follows:

import panel as pn
import holoviews as hv
hv.extension('bokeh')

checkbox = pn.widgets.Checkbox(name='My Checkbox')
selector = pn.widgets.Select(options=['a','b','c'], name='My Selector')

def callback(my_selector, my_checkbox):
    return hv.Curve([1,2,3])

hv.DynamicMap(callback, streams=[checkbox, selector])

This would be orthogonal to other approaches such as pn.bind (which should also be available from param, without special widget support). For me this approach would feel very natural and I don’t think it precludes any other of the available approaches.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:4
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
jlstevenscommented, Jan 8, 2021

One idea I quite like is to note that the streams parameter only supports lists for historical reasons:

    streams = param.List(default=[], constant=True, doc="""
       List of Stream instances to associate with the DynamicMap. The
       set of parameter values across these streams will be supplied as
       keyword arguments to the callback when the events are received,
       updating the streams.""" )

Supporting a dict here would take a lot of the pain away imho and would be a great improvement for HoloViews generally (and would avoid the need for bind in many cases):

checkbox = pn.widgets.Checkbox(name='My Boolean')
selector = pn.widgets.Select(options=['a','b','c'], name='My Value')

def callback(selector, like_and_subcribe):
    return hv.Curve([1,2,3])

hv.DynamicMap(callback, streams=dict(selector=selector_widget, like_and_subcribe=checkbox))

Implementing this would make this issue mostly moot as this dict could support parameters or panel widgets as values (holoviews streams here become tricky for streams with multiple parameters).

1reaction
philippjfrcommented, Jan 8, 2021

I still think panel widgets should be allowed to have user specified identifiers.

Please file an issue about that. We do have a mechanism to query any panel object for subobjects matching some criteria using the .select method (modeled after bokeh’s Model.select) and I would quite happily support for having an id attribute or similar. The main concern here is that it cannot clash with any existing parameter in Panel.

Read more comments on GitHub >

github_iconTop Results From Across the Web

panel.widgets Package — Panel v0.14.1
ValueError – Raised if the stream_value is not a supported type.: Examples. Stream a Series to a DataFrame >>> value = pd.DataFrame({“x”: [1,...
Read more >
Overview — Panel v0.14.2
Panel : A Panel is a hierarchical container to lay out multiple components (panes, widgets, or other Panel s) into an arrangement that...
Read more >
APIs — Panel v0.14.2
APIs# · Interact functions: Auto-generates a full UI (including widgets) given a function · Reactive functions: Linking functions or methods to widgets using...
Read more >
Select — Panel v0.14.2
size is set to a value greater than 1 the widget supports the ; disabled_options parameter but does not support ; groups ....
Read more >
Component overview — Panel v0.14.2
Widget objects provide controls that can trigger Python or JavaScript events. Panel layout objects allow combining plots into a Row , Column ,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found