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

Ensure DynamicMap updates when widget dimension has unit #5904

Merged
merged 2 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion panel/pane/holoviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,9 @@ def _update_plot(self, plot, pane):
key = tuple(w.value for w in widgets)
if plot.dynamic:
widget_dims = [w.name for w in widgets]
dim_labels = [kdim.pprint_label for kdim in plot.dimensions]
key = [key[widget_dims.index(kdim)] if kdim in widget_dims else None
for kdim in plot.dimensions]
for kdim in dim_labels]
key = wrap_tuple_streams(tuple(key), plot.dimensions, plot.streams)

if plot.backend == 'bokeh':
Expand Down
18 changes: 18 additions & 0 deletions panel/tests/pane/test_holoviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ def test_holoviews_updates_widgets(document, comm):
assert isinstance(layout.children[1].children[0], BkColumn)
assert isinstance(layout.children[1].children[0].children[1], BkSlider)


@hv_available
def test_holoviews_widgets_update_plot(document, comm):
hmap = hv.HoloMap({(i, chr(65+i)): hv.Curve([i]) for i in range(3)}, kdims=['X', 'Y'])
Expand All @@ -327,6 +328,23 @@ def test_holoviews_widgets_update_plot(document, comm):
assert cds.data['y'] == np.array([1])


@hv_available
def test_holoviews_dynamic_widgets_with_unit_updates_plot(document, comm):
def function(f):
return hv.Curve((x, np.sin(f*x)))

x = np.linspace(0, 10)
factor = hv.Dimension('factor', unit='m', values=[1, 2, 3, 4, 5])
dmap = hv.DynamicMap(function, kdims=factor)
hv_pane = HoloViews(dmap, backend='bokeh')
layout = hv_pane.get_root(document, comm)

cds = layout.children[0].select_one({'type': ColumnDataSource})
np.testing.assert_array_equal(cds.data['y'], np.sin(x))
hv_pane.widget_box[0].value = 3
np.testing.assert_array_equal(cds.data['y'], np.sin(3*x))


@hv_available
def test_holoviews_with_widgets_not_shown(document, comm):
hmap = hv.HoloMap({(i, chr(65+i)): hv.Curve([i]) for i in range(3)}, kdims=['X', 'Y'])
Expand Down