Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for "running" callback argument. #510

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions django_plotly_dash/_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ def register_callback(
insert_output = flatten_grouping(output)
multi = True

running = _kwargs.get("running")
if running is not None:
if not isinstance(running[0], (list, tuple)):
running = [running]
running = {
"running": {str(r[0]): r[1] for r in running},
"runningOff": {str(r[0]): r[2] for r in running},
}

output_indices = make_grouping_by_index(output, list(range(grouping_len(output))))
callback_id = insert_callback(
callback_list,
Expand All @@ -62,6 +71,7 @@ def register_callback(
flat_state,
inputs_state_indices,
prevent_initial_call,
running=running,
)

# pylint: disable=too-many-locals
Expand Down
13 changes: 11 additions & 2 deletions django_plotly_dash/dash_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,9 @@ def callback(self, *_args, **_kwargs):
'state': state,
'prevent_initial_call': prevent_initial_call}

if 'running' in _kwargs:
callback_set['running'] = _kwargs['running']

def wrap_func(func):
self._callback_sets.append((callback_set, func))
# add an expanded attribute to the function with the information to use in dispatch_with_args
Expand Down Expand Up @@ -601,18 +604,24 @@ def _fix_callback_item(self, item):
item.component_id = self._fix_id(item.component_id)
return item

def callback(self, output, inputs, state, prevent_initial_call):
def callback(self, output, inputs, state, prevent_initial_call, running=None):
'Invoke callback, adjusting variable names as needed'

if isinstance(output, (list, tuple)):
fixed_outputs = [self._fix_callback_item(x) for x in output]
else:
fixed_outputs = self._fix_callback_item(output)

if isinstance(running, list):
fixed_running = [(self._fix_callback_item(out), on, off) for out, on, off in running]
else:
fixed_running = running

return super().callback(fixed_outputs,
[self._fix_callback_item(x) for x in inputs],
[self._fix_callback_item(x) for x in state],
prevent_initial_call=prevent_initial_call)
prevent_initial_call=prevent_initial_call,
running=fixed_running)

def clientside_callback(self, clientside_function, output, inputs, state, prevent_initial_call): # pylint: disable=dangerous-default-value
'Invoke callback, adjusting variable names as needed'
Expand Down