I'm trying to adapt the example here: http://pyviz.org/tutorial/A2_Dashboard_Workflow.html to my own data and requirements.
As a simple test I tried the following:
import panel as pp
import param
df = load_some_data
parameter_1_list = df.parameter1.unique()
parameter_2_list = df.parameter2.unique()
class EventExplorer(param.Parameterized):
parameter1 = param.ObjectSelector(default=parameter1_list[0], objects=parameter1_list)
parameter2 = param.ObjectSelector(default=parameter2_list[0], objects=parameter2_run_list)
def make_view(self, **kwargs):
Subset_Data = df.loc[(df['a_column']==self.parameter1[:2])&(df['a_column']==self.parameter1[2:])&(df['a_column']==self.parameter2)]
output = DATA.hvplot.line(x='a_channel', y=self.parameter1)
return output
pp.Row(EventExplorer.param, EventExplorer.make_view())
If I run the param method alone I get the drop-downs I expect, populated in the way I expect.
But if I run the code as I have here I get:
name 'self' is not defined
Related to the row where I create Subset_Data. This is likely to be more an issue on my side with classes, etc. But would be good to get some feedback.
Ben
EventExplorer here is a class, and you have to make an instance of the class before you can call a method on it (hence the complaint from Python about "self", which doesn't exist on classes). If you want to call the method, first make an instance of the class, e.g. ee=EventExplorer()
, and then you can do pp.Row(ee.param, ee.make_view())
.
That said, in this case you probably don't want to be calling the method anyway; I'd guess from the code that you were hoping Panel would call the method whenever one of the parameters changes. If that's what you want, you have to provide the method itself to panel, not the result of calling the method: (pp.Row(ee.param, ee.make_view)
). Sometimes you do want to evaluate the method manually as you did, so that you get the return value, if you are using other ways such as HoloViews streams to connect the parameters to the displayed object. It's hard to tell without runnable code, but here those other approaches don't seem relevant because you have code inside the method that directly depends on the parameters, and so the method needs re-running each time one of those parameters changes.