Player widget use inside class

Hello, I am trying to include Player widget inside a class based on the example in docs (Vtk — Panel 0.12.0 documentation). I adapted myself to work with displaying a .stl inside vtk pane and rotated with player widget. This adapted code works and looks like:

import pyvista as pv
import panel as pn
pn.extension('vtk')

tube = pv.read("/home/toni/Documentos/CAD/caja.stl")

plotter = pv.Plotter()

plotter.add_mesh(tube)

pan = pn.panel(plotter.ren_win, width=500, orientation_widget=True)

pan.synchronize()

pan_clone = pan.clone() # we clone the panel to animate only this panel
pan_clone.unlink_camera() # we don't want to share the camera with the previous panel
player = pn.widgets.Player(name='Player', start=0, end=100, value=0, loop_policy='reflect', interval=100)

@pn.depends(value=player.param.value)

def animate(value):
    pan_clone.actors[0].SetOrientation(0, 0, -20*value)
    pan_clone.synchronize()

sin = pn.Column(pan_clone, player, animate).servable()

sin.show()

Looking at some tutorials about using widget as param to work better into class I have rewritten previous code, but unfortunately cannot work. This is what I have now.

import pyvista as pv
import panel as pn
pn.extension('vtk')

class Graph(param.Parameterized):
    tube = pv.read("/home/toni/Documentos/CAD/caja.stl")
    #player = param.Integer(0, bounds=(0, 100))
    player = param.Parameter() 

    def __init__(self):
        #super().__init__()
        self.plotter = pv.Plotter()
        self.plotter.add_mesh(self.tube)
        self.pan = pn.panel(self.plotter.ren_win, 
                            width=1500, 
                            orientation_widget=True)

        self.pan.synchronize()

        self.pan_clone = self.pan.clone() # we clone the panel to animate only this panel
        self.pan_clone.unlink_camera() # we don't want to share the camera with the previous panel
        self.param.player = pn.widgets.Player(name='Player', 
                                              start=0, end=100, value=0, 
                                              loop_policy='reflect', interval=100)


    @pn.depends('player.value', watch = True)
    def animate(self):
        self.pan_clone.actors[0].SetOrientation(0, 30, -20*value)
        self.pan_clone.synchronize()
        sin = pn.Column(pan_clone, self.param.player, animate).servable()
        return sin


a = Graph()


sin = a.animate()
sin.show()

Do you know where I am making a mistake? Is this kind of implementation possible?

Thanks for your help.

I have found a solution to this issue myself. I hope it helps someone:

import numpy as np
import param

v = np.arange(0,75)

class CustomExample(param.Parameterized):
    """An example Parameterized class"""

    player = param.Selector(objects=v)
    txt = param.String("Muestra")
    
    def __init__(self):
        super().__init__()
        self.tube = pv.read("/home/toni/CAD/caja.stl")
        self.plotter = pv.Plotter()
        self.plotter.add_mesh(self.tube)
        self.pan = pn.panel(self.plotter.ren_win, width=500, orientation_widget=True)

        self.pan_clone = self.pan.clone() # we clone the panel to animate only this panel
        self.pan_clone.unlink_camera() # we don't want to share the camera with the previous panel
        
    @param.depends('player', watch = True)
    def vtk(self):     
        
        if self.player == None:
            pass
        else:
            
            self.pan_clone.actors[0].SetOrientation(0, 30, 12*self.player)
            self.pan_clone.synchronize()
            
            self.txt = str(self.player)
    
    def panel(self):
        return pn.Column(self.pan_clone,
                         pn.Param(self.param, widgets={'player': pn.widgets.DiscretePlayer}), 
                         self.vtk,
                        )


a = CustomExample()
vtk = a.panel()
vtk.show()