Skip to content

Commit a8343dd

Browse files
author
Mark Gibbs
committed
Added callback variant with kwargs added onto function signature
1 parent 8332282 commit a8343dd

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

demo/demo/plotly_apps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def callback_size(dropdown_color, dropdown_size):
4444
html.Div(id="output-one")
4545
])
4646

47-
@a2.callback(
47+
@a2.expanded_callback(
4848
dash.dependencies.Output('output-one','children'),
4949
[dash.dependencies.Input('dropdown-one','value')]
5050
)

django_plotly_dash/dash_wrapper.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,12 @@ def __init__(self, name=None, **kwargs):
5858
global usable_apps
5959
usable_apps[self._uid] = self
6060

61+
self._expanded_callbacks = False
62+
6163
def form_dash_instance(self):
6264
rd = NotDash(name_root=self._uid,
63-
app_pathname="%s:main" % app_name)
65+
app_pathname="%s:main" % app_name,
66+
expanded_callbacks = self._expanded_callbacks)
6467
rd.layout = self.layout
6568

6669
for cb, func in self._callback_sets:
@@ -82,6 +85,10 @@ def wrap_func(func,callback_set=callback_set,callback_sets=self._callback_sets):
8285
return func
8386
return wrap_func
8487

88+
def expanded_callback(self, output, inputs=[], state=[], events=[]):
89+
self._expanded_callbacks = True
90+
return self.callback(output, inputs, state, events)
91+
8592
class NotFlask:
8693
def __init__(self):
8794
self.config = {}
@@ -124,7 +131,7 @@ def __init__(self, name_root, app_pathname, **kwargs):
124131
nd_apps[self._uid] = self
125132

126133
self._adjust_id = False
127-
self._dash_dispatch = False
134+
self._dash_dispatch = not kwargs.get('expanded_callbacks',False)
128135

129136
def use_dash_dispatch(self):
130137
# TODO make this be a function of using kwargs in callbacks

django_plotly_dash/views.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def dependencies(request, id, **kwargs):
1919
def layout(request, id, **kwargs):
2020
app = get_app_instance_by_id(id)
2121
mFunc = app.locate_endpoint_function('dash-layout')
22-
resp = mFunc()
22+
resp = mFunc() # bytes that is json encoded layout
2323
return HttpResponse(resp.data,
2424
content_type=resp.mimetype)
2525

@@ -37,8 +37,10 @@ def update(request, id, **kwargs):
3737
flask.request._cached_json = (rb, flask.request._cached_json[True])
3838
resp = mFunc()
3939
else:
40-
# Use direct dispatch
41-
argMap = {}
40+
# Use direct dispatch with extra arguments in the argMap
41+
argMap = {'id':id,
42+
'request':request,
43+
'session':request.session}
4244
resp = app.dispatch_with_args(rb, argMap)
4345

4446
return HttpResponse(resp.data,

0 commit comments

Comments
 (0)