Comments (2)
Thinking about it more.. I guess this is probably beyond what param/panel could reasonably provide and would probably require an ad hoc global event dispatcher of some sort.
I think I just need to adjust my mental model of how to architect an advanced panel app... just don't exactly understand how yet
from param.
Here is a a solution.. creating another class as the global state and then passing an instance of that state object to each of the Parents, Child instances. Now, triggering any of the slider widgets results in printing 'triggered in Parent' 3 times and 'triggered in Child B' once... which I guess is the unavoidable compromise for this solution. muy complicado
import param
from panel.viewable import Viewer
import panel as pn; pn.extension()
class SharedState(param.Parameterized):
slider_vals = param.Number(default=2.0, bounds=(0.1, 5.0))
trig = param.Event()
class Parent(Viewer):
state = param.ClassSelector(class_=SharedState)
def __init__(self, **params):
super().__init__(**params)
@param.depends('state.slider_vals', watch=True)
def trigger(self):
self.state.trig = True
# self.param.trigger('state.trig')
@param.depends('state.trig', watch=True)
def print_trig_P(self):
print('triggered in Parent')
def __controls__(self):
return pn.Row(pn.widgets.FloatSlider.from_param(self.state.param.slider_vals))
class ChildA(Parent):
def __init__(self, **params):
super().__init__(**params)
def __controls__(self):
return pn.Row(pn.widgets.FloatSlider.from_param(self.state.param.slider_vals))
class ChildB(Parent):
def __init__(self, **params):
super().__init__(**params)
@param.depends('state.trig', watch=True)
def print_trig_B(self):
print('triggered in Child B')
def __controls__(self):
return pn.Row(pn.widgets.FloatSlider.from_param(self.state.param.slider_vals))
@param.depends('state.trig', watch=True)
def __panel__(self):
return pn.pane.Markdown('Child B triggered!')
state = SharedState()
parent = Parent(state=state)
child_a = ChildA(state=state)
child_b = ChildB(state=state)
pn.Column(child_a.__controls__(), parent.__controls__(), child_b.__controls__()).servable()
from param.
Related Issues (20)
- Param with bounds should default to lower bound HOT 7
- Add .is_active parameter to reactive expressions HOT 3
- Let reactive expressions .watch method support async functions
- Context manager .param.update should restore references
- Let pn.Param accept a list of objects HOT 1
- Warn on errors thru rx updates
- Make param.depends efficient HOT 6
- Parameter called outputs does not work with `.rx` HOT 4
- Initialization changes constant attribute. HOT 3
- Missing `param_help.png` in `User Guide/Parameters`
- Discussion about the intro video HOT 1
- Should methods on Parameterizeds be treated as references by default HOT 3
- `name` of a Parameterized instance overridden when is the default of a `readonly/constant` Parameter HOT 2
- Error on printing rx
- RX: output not updated when indexing a DataFrame with value_start/value_end HOT 1
- Small text issue in doc Getting Started
- Ability to specify multiple classes in class_ for ClassSelector parameter type needs to be documented
- Cannot use param.Parameterized inheritance when inheriting alongside abstract classes
- Getting a "'_thread.RLock'" object error when instantiating a LangChain model as a default object
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from param.