diff --git a/holoviews/core/accessors.py b/holoviews/core/accessors.py index 4afcf954ca..a0c0cf92f2 100644 --- a/holoviews/core/accessors.py +++ b/holoviews/core/accessors.py @@ -3,11 +3,14 @@ """ from __future__ import absolute_import, unicode_literals +import copy +import sys + from collections import OrderedDict from types import FunctionType -import copy import param + from param.parameterized import add_metaclass from . import util @@ -156,6 +159,11 @@ def function(object, **kwargs): method_name) return method(*args, **kwargs) + if 'panel' in sys.modules: + from panel.widgets.base import Widget + kwargs = {k: v.param.value if isinstance(v, Widget) else v + for k, v in kwargs.items()} + applies = isinstance(self._obj, ViewableElement) params = {p: val for p, val in kwargs.items() if isinstance(val, param.Parameter) diff --git a/holoviews/tests/core/testapply.py b/holoviews/tests/core/testapply.py index 91c10952b0..ea1ae06ecc 100644 --- a/holoviews/tests/core/testapply.py +++ b/holoviews/tests/core/testapply.py @@ -1,6 +1,8 @@ import numpy as np import param +from panel.widgets import TextInput + from holoviews.core.spaces import DynamicMap, HoloMap from holoviews.element import Image, Curve from holoviews.element.comparison import ComparisonTestCase @@ -57,6 +59,14 @@ def test_element_apply_dynamic(self): self.assertEqual(len(applied.streams), 0) self.assertEqual(applied[()], self.element.relabel('Test')) + def test_element_apply_dynamic_with_widget_kwarg(self): + text = TextInput() + applied = self.element.apply(lambda x, label: x.relabel(label), label=text) + self.assertEqual(len(applied.streams), 1) + self.assertEqual(applied[()].label, '') + text.value = 'Test' + self.assertEqual(applied[()].label, 'Test') + def test_element_apply_dynamic_with_kwarg(self): applied = self.element.apply(lambda x, label: x.relabel(label), dynamic=True, label='Test') self.assertEqual(len(applied.streams), 0)