Classes and its features

Hi everybody,
I wonder at what stage of dashboard development you guys think that it is necessery to implement classes in the script. There are both, big examples which implement the function inside of classes as well as examples where the data and visualisation features are just declared by functions without individual classes.
Maybe it is a newbie question but since I am working on a bigger project and my python skills are at a low level, I hope that the community can give me some advise about the pros and cons of implementing classes.
In my post about the value of a RangeSlider (Get the Values of a Rangeslider) I got two resonable answers. One with implementing a class and one without.
What are your criteria to use classes instead of plain functions?

I think both approaches are reasonable. I am familiar with Classes and like that approach but others like a more functional approach.

I have seen beginners in Python and Panel struggle because I showed them the Class based approach. So I think that might not be the right starting point.

I think a good functional approach is to

  1. Define functions to get data
  2. Define functions to get plots
  3. Create widgets and functions that depends on those widgets
  4. Create functions to create layouts

Run the app. When you have this and is familiar with classes you might refactor a bit.

1 Like

Hi Marc,
thank you for replying. Maybe its good to use classes when one plans to reuse or extend the structure of the panel/map/whatever with other data.
Do you think that there are any restrictions that can be put away by using classes?

1 Like

Yes. I use classes because I want to create reusable components and apps. So when I’ve gotten used to it, I just to it also for simple, quick things even though it might not be needed.