Setting it before the super init then it all seems to click,
# Imports
from io import StringIO
import pandas as pd
import param
import holoviews as hv
import panel as pn
from collections import defaultdict
hv.extension()
pn.extension()
# Setting up test data
data_text = (
"""
sensor| a| b| c| e
s1| 7.| 2.| 3.| 11.
s1| 3.| 4.| 4.| 2.
s1| .5| 2.| 3.| 5.
s2| 2.| 3.| 2.| 1.
s2| 1.| 7.| 2.| -2.
s2| 1.| 2.| 1.| 0.
""")
df = pd.read_csv(StringIO(data_text), sep='|', skipinitialspace=True)
# setting up predefined options as a list of lists where each inner list is a pair of column names from dataframe.
pairs_custom = [
#[], # list doesn't select until new option is selected, give it empty as default
['a', 'b'],
['b', 'c'],
['a', 'c']
]
# My best attempt so far (trying to read up on different challenges.
class Viewer2(param.Parameterized):
pair = param.ObjectSelector() # (objects={'A': ['a', 'c']}, default=['a', 'c'])
def __init__(self, pairs, **params):
new_opts = {', '.join(v): v for v in pairs}
self.param.pair.names = new_opts
self.param.pair.objects = list(new_opts.values())
self.param.pair.default = list(new_opts.values())[0]
super().__init__(**params, name='Test viewer second example')
# pair = param.ObjectSelector(objects=self.pairs_custom) # This one can not reach to self and cannot be used it seems
@param.depends('pair')
def view(self):
return hv.Points(df, kdims=self.pair)
viewer_flexible = Viewer2(pairs=pairs_custom)
I think I’ve read material from maybe @Marc on this before somewhere, it’s beyond me to be able to explain
I think this is it https://discourse.holoviz.org/t/placement-of-super/2996/7