Skip to content

Commit 79f8c24

Browse files
committed
🐎 clientside callback interface
see associated PR & examples in plotly/dash-renderer#143
1 parent 0812b1a commit 79f8c24

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

dash/dash.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,7 @@ def dependencies(self):
631631
'output': k,
632632
'inputs': v['inputs'],
633633
'state': v['state'],
634+
'client_function': v['client_function']
634635
} for k, v in self.callback_map.items()
635636
])
636637

@@ -946,7 +947,7 @@ def _validate_value(val, index=None):
946947
# TODO - Check this map for recursive or other ill-defined non-tree
947948
# relationships
948949
# pylint: disable=dangerous-default-value
949-
def callback(self, output, inputs=[], state=[]):
950+
def callback(self, output, inputs=[], state=[], client_function=None):
950951
self._validate_callback(output, inputs, state)
951952

952953
callback_id = _create_callback_id(output)
@@ -960,8 +961,16 @@ def callback(self, output, inputs=[], state=[]):
960961
'state': [
961962
{'id': c.component_id, 'property': c.component_property}
962963
for c in state
963-
]
964+
],
964965
}
966+
if client_function is not None:
967+
self.callback_map[callback_id]['client_function'] = {
968+
'namespace': client_function.namespace,
969+
'function_name': client_function.function_name
970+
}
971+
else:
972+
self.callback_map[callback_id]['client_function'] = {}
973+
965974

966975
def wrap_func(func):
967976
@wraps(func)

dash/dependencies.py

+13
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,16 @@ class Input(DashDependency):
3232
# pylint: disable=too-few-public-methods
3333
class State(DashDependency):
3434
"""Use the value of a state in a callback but don't trigger updates."""
35+
36+
37+
# pylint: disable=too-few-public-methods
38+
class ClientFunction:
39+
def __init__(self, namespace=None, function_name=None):
40+
self.namespace = namespace
41+
self.function_name = function_name
42+
43+
def __repr__(self):
44+
return 'ClientFunction({}, {})'.format(
45+
self.namespace,
46+
self.function_name
47+
)

0 commit comments

Comments
 (0)