2727import itertools
2828import json
2929import inspect
30+ import warnings
3031
3132import dash
3233from dash import Dash
5051 from dataclasses import dataclass
5152 from typing import Dict , List
5253
53- @dataclass (frozen - True )
54+ @dataclass (frozen = True )
5455 class CallbackContext :
5556 inputs_list : List
5657 inputs : Dict
@@ -162,7 +163,17 @@ class DjangoDash:
162163 def __init__ (self , name = None , serve_locally = None ,
163164 add_bootstrap_links = False ,
164165 suppress_callback_exceptions = False ,
165- ** kwargs ): # pylint: disable=unused-argument, too-many-arguments
166+ external_stylesheets = None ,
167+ external_scripts = None ,
168+ ** kwargs ): # pylint: disable=unused-argument, too-many-arguments
169+
170+ # store arguments to pass them later to the WrappedDash instance
171+ self .external_stylesheets = external_stylesheets or []
172+ self .external_scripts = external_scripts or []
173+ self ._kwargs = kwargs
174+ if kwargs :
175+ warnings .warn ("You are passing extra arguments {kwargs} that will be passed to Dash(...) "
176+ "but may not be properly handled by django-plotly-dash." .format (kwargs = kwargs ))
166177
167178 if name is None :
168179 global uid_counter # pylint: disable=global-statement
@@ -268,7 +279,10 @@ def form_dash_instance(self, replacements=None, ndid=None, base_pathname=None):
268279 rd = WrappedDash (base_pathname = base_pathname ,
269280 replacements = replacements ,
270281 ndid = ndid ,
271- serve_locally = self ._serve_locally )
282+ serve_locally = self ._serve_locally ,
283+ external_stylesheets = self .external_stylesheets ,
284+ external_scripts = self .external_scripts ,
285+ ** self ._kwargs )
272286
273287 rd .layout = self .layout
274288 rd .config ['suppress_callback_exceptions' ] = self ._suppress_callback_exceptions
@@ -408,8 +422,7 @@ def __init__(self,
408422 kwargs ['url_base_pathname' ] = self ._base_pathname
409423 kwargs ['server' ] = self ._notflask
410424
411- super (WrappedDash , self ).__init__ (__name__ ,
412- ** kwargs )
425+ super ().__init__ (__name__ , ** kwargs )
413426
414427 self .css .config .serve_locally = serve_locally
415428 self .scripts .config .serve_locally = serve_locally
@@ -577,9 +590,9 @@ def callback(self, output, inputs=[], state=[], events=[]): # pylint: disable=da
577590 else :
578591 fixed_outputs = self ._fix_callback_item (output )
579592
580- return super (WrappedDash , self ).callback (fixed_outputs ,
581- [self ._fix_callback_item (x ) for x in inputs ],
582- [self ._fix_callback_item (x ) for x in state ])
593+ return super ().callback (fixed_outputs ,
594+ [self ._fix_callback_item (x ) for x in inputs ],
595+ [self ._fix_callback_item (x ) for x in state ])
583596
584597 def clientside_callback (self , clientside_function , output , inputs = [], state = []): # pylint: disable=dangerous-default-value
585598 'Invoke callback, adjusting variable names as needed'
@@ -589,10 +602,10 @@ def clientside_callback(self, clientside_function, output, inputs=[], state=[]):
589602 else :
590603 fixed_outputs = self ._fix_callback_item (output )
591604
592- return super (WrappedDash , self ).clientside_callback (clientside_function ,
593- fixed_outputs ,
594- [self ._fix_callback_item (x ) for x in inputs ],
595- [self ._fix_callback_item (x ) for x in state ])
605+ return super ().clientside_callback (clientside_function ,
606+ fixed_outputs ,
607+ [self ._fix_callback_item (x ) for x in inputs ],
608+ [self ._fix_callback_item (x ) for x in state ])
596609
597610 def dispatch (self ):
598611 'Perform dispatch, using request embedded within flask global state'
@@ -750,7 +763,7 @@ def index(self, *args, **kwargs): # pylint: disable=unused-argument
750763 def interpolate_index (self , ** kwargs ): #pylint: disable=arguments-differ
751764
752765 if not self ._return_embedded :
753- resp = super (WrappedDash , self ).interpolate_index (** kwargs )
766+ resp = super ().interpolate_index (** kwargs )
754767 return resp
755768
756769 self ._return_embedded .add_css (kwargs ['css' ])
0 commit comments