Skip to content

Commit

Permalink
Ensure that widget passed as apply kwarg is treated as dynamic input (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Jan 6, 2020
1 parent 2259e5e commit 85f5dd0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
10 changes: 9 additions & 1 deletion holoviews/core/accessors.py
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions 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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 85f5dd0

Please sign in to comment.