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.

pn.widgets not working in a list

See original GitHub issue

Hi, I’m trying out the hvplot .interactive. I got TypeError: ‘RadioButtonGroup’ object is not callable for the following code, I think it’s because I can’t write my xaxis in a list. It works if I change .groupby(['origin', xaxis]) to .groupby(xaxis), but it’d be nice if pn.widgets can work in a list. I’d really appreciate some help. Thanks!

from bokeh.sampledata.autompg import autompg_clean as df
import hvplot.pandas
import panel as pn
import holoviews as hv
hv.extension('bokeh')
idf = df.interactive()
cylinders = pn.widgets.IntSlider(start=4, end=8, step=2)
mfr = pn.widgets.ToggleGroup(options=['ford', 'chevrolet', 'plymouth', 'honda', 'sbaru', 'volkswagen'], 
                             value=['ford', 'chevrolet', 'plymouth', 'honda', 'sbaru', 'volkswagen'])
xaxis = pn.widgets.RadioButtonGroup(name='X axis', options=['mpg', 'yr'])
yaxis = pn.widgets.RadioButtonGroup(name='Y axis', options=['hp', 'weight'])

ipipeline = (
    idf[
        (idf.cyl == cylinders) & 
        (idf.mfr.isin(mfr))
    ]
    .groupby(['origin', xaxis])[yaxis].mean()
    .to_frame()
    .reset_index()
)

image

Traceback
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/var/folders/n9/dr352bs550nck1fg2mz9vpn80000gn/T/ipykernel_46537/1739249479.py in <module>
     12 
     13 ipipeline = (
---> 14     idf[
     15         (idf.cyl == cylinders) &
     16         (idf.mfr.isin(mfr))

/opt/anaconda3/envs/p39/lib/python3.9/site-packages/hvplot/interactive.py in __call__(self, *args, **kwargs)
    185                                        accessor=True)
    186             kwargs = dict(self._inherit_kwargs, **kwargs)
--> 187             clone = self._clone(method(*args, **kwargs), plot=self._method == 'plot')
    188         finally:
    189             self._method = None

/opt/anaconda3/envs/p39/lib/python3.9/site-packages/hvplot/interactive.py in _clone(self, transform, plot, loc, center, dmap, **kwargs)
    114         depth = self._depth+1
    115         kwargs = dict(self._inherit_kwargs, **dict(self._kwargs, **kwargs))
--> 116         return type(self)(self._obj, transform, plot, depth,
    117                           loc, center, dmap, **kwargs)
    118 

/opt/anaconda3/envs/p39/lib/python3.9/site-packages/hvplot/interactive.py in __init__(self, obj, transform, plot, depth, loc, center, dmap, inherit_kwargs, max_rows, **kwargs)
     84         self._kwargs = kwargs
     85         ds = hv.Dataset(self._obj)
---> 86         self._current = self._transform.apply(ds, keep_index=True, compute=False)
     87         self._init = True
     88 

/opt/anaconda3/envs/p39/lib/python3.9/site-packages/holoviews/util/transform.py in apply(self, dataset, flat, expanded, ranges, all_values, keep_index, compute, strict)
    736             drange = ranges.get(eldim, {})
    737             drange = drange.get('combined', drange)
--> 738             data = self._apply_fn(dataset, data, fn, fn_name, args,
    739                                   kwargs, accessor, drange)
    740         drop_index = keep_index_for_compute and not keep_index

/opt/anaconda3/envs/p39/lib/python3.9/site-packages/holoviews/util/transform.py in _apply_fn(self, dataset, data, fn, fn_name, args, kwargs, accessor, drange)
    634                         data = method(*args, **kwargs)
    635                     else:
--> 636                         raise e
    637         else:
    638             data = fn(*args, **kwargs)

/opt/anaconda3/envs/p39/lib/python3.9/site-packages/holoviews/util/transform.py in _apply_fn(self, dataset, data, fn, fn_name, args, kwargs, accessor, drange)
    628             else:
    629                 try:
--> 630                     data = method(*args, **kwargs)
    631                 except Exception as e:
    632                     if 'axis' in kwargs:

/opt/anaconda3/envs/p39/lib/python3.9/site-packages/pandas/core/frame.py in groupby(self, by, axis, level, as_index, sort, group_keys, squeeze, observed, dropna)
   7624         # error: Argument "squeeze" to "DataFrameGroupBy" has incompatible type
   7625         # "Union[bool, NoDefault]"; expected "bool"
-> 7626         return DataFrameGroupBy(
   7627             obj=self,
   7628             keys=by,

/opt/anaconda3/envs/p39/lib/python3.9/site-packages/pandas/core/groupby/groupby.py in __init__(self, obj, keys, axis, level, grouper, exclusions, selection, as_index, sort, group_keys, squeeze, observed, mutated, dropna)
    886             from pandas.core.groupby.grouper import get_grouper
    887 
--> 888             grouper, exclusions, obj = get_grouper(
    889                 obj,
    890                 keys,

/opt/anaconda3/envs/p39/lib/python3.9/site-packages/pandas/core/groupby/grouper.py in get_grouper(obj, key, axis, level, sort, observed, mutated, validate, dropna)
    875         # allow us to passing the actual Grouping as the gpr
    876         ping = (
--> 877             Grouping(
    878                 group_axis,
    879                 gpr,

/opt/anaconda3/envs/p39/lib/python3.9/site-packages/pandas/core/groupby/grouper.py in __init__(self, index, grouper, obj, level, sort, observed, in_axis, dropna)
    533                 raise ValueError(f"Grouper for '{t}' not 1-dimensional")
    534 
--> 535             self.grouping_vector = index.map(self.grouping_vector)
    536 
    537             if not (

/opt/anaconda3/envs/p39/lib/python3.9/site-packages/pandas/core/indexes/base.py in map(self, mapper, na_action)
   5505         from pandas.core.indexes.multi import MultiIndex
   5506 
-> 5507         new_values = self._map_values(mapper, na_action=na_action)
   5508 
   5509         attributes = self._get_attributes_dict()

/opt/anaconda3/envs/p39/lib/python3.9/site-packages/pandas/core/base.py in _map_values(self, mapper, na_action)
    868 
    869         # mapper is a function
--> 870         new_values = map_f(values, mapper)
    871 
    872         return new_values

/opt/anaconda3/envs/p39/lib/python3.9/site-packages/pandas/_libs/lib.pyx in pandas._libs.lib.map_infer()

TypeError: 'RadioButtonGroup' object is not callable

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
Hoxbrocommented, Jan 17, 2022

No problem, glad I could help - so you’re able to share with the world how awesome the holoviz stack is.

3reactions
Hoxbrocommented, Jan 17, 2022

The reason why is the plot is not updating when I change the cylinder slider is that both it and the mfr toggle group have no name. This means that if I change the order of them in the ipipeline it is the toggle group which becomes unresponsive. If I give one of the widget a name both of them will work. This should be fixed upstream in holoviews to avoid it overwriting widgets with no (or the same name).

Read more comments on GitHub >

github_iconTop Results From Across the Web

widgets not getting displayed in ipywidgets - Stack Overflow
I tried the following (as advised in a youtube video - the sole teacher available for me). import ipywidgets as widgets from IPython.display ......
Read more >
Widgets — Panel v0.14.2
Multiple values. These widgets allow selecting multiple values from a list or dictionary of options: CheckBoxGroup : Select values by ticking the corresponding ......
Read more >
The 2 alternative approaches for Jupyter Notebook widgets
The first approach is to use ipywidgets and Voila framework. The ipywidgets provides a way to add widgets in the notebook with Python....
Read more >
Installation — Jupyter Widgets 7.7.2 documentation
The location of the lab directory can be queried by executing the command jupyter lab path in your terminal. Frequently Asked Questions¶. The...
Read more >
Jupyter Widgets
if not os.path.exists("mauna_loa_data.npz"): import urllib.request tmp ... You have seen how the checkbox and textarea widgets work above.
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