@@ -136,6 +136,11 @@ class VisualizationElement:
136
136
local_includes: A list of JavaScript and CSS files that are local to
137
137
the directory that the server is being run in.
138
138
js_code: A JavaScript code string to instantiate the element.
139
+ local_dir: A full path to the directory containing the local includes.
140
+ If a relative path is given, it is relative to the working
141
+ directory where the server is being run. If an absolute path
142
+ is given, it is used as-is. Default is the current working
143
+ directory.
139
144
140
145
Methods:
141
146
render: Takes a model object, and produces JSON data which can be sent
@@ -147,6 +152,7 @@ class VisualizationElement:
147
152
local_includes = []
148
153
js_code = ""
149
154
render_args = {}
155
+ local_dir = ""
150
156
151
157
def __init__ (self ):
152
158
pass
@@ -291,13 +297,7 @@ def __init__(
291
297
tornado .web .StaticFileHandler ,
292
298
{"path" : os .path .dirname (__file__ ) + "/templates" },
293
299
)
294
- local_handler = (
295
- r"/local/(.*)" ,
296
- tornado .web .StaticFileHandler ,
297
- {"path" : "" },
298
- )
299
-
300
- self .handlers = [page_handler , socket_handler , static_handler , local_handler ]
300
+ self .handlers = [page_handler , socket_handler , static_handler ]
301
301
302
302
self .settings = {
303
303
"debug" : True ,
@@ -323,11 +323,20 @@ def __init__(
323
323
self .package_css_includes .add (include_file )
324
324
else :
325
325
self .package_js_includes .add (include_file )
326
- for include_file in element .local_includes :
327
- if self ._is_stylesheet (include_file ):
328
- self .local_css_includes .add (include_file )
329
- else :
330
- self .local_js_includes .add (include_file )
326
+ if element .local_includes :
327
+ mapped_local_dir = element .__class__ .__name__
328
+ element_file_handler = (
329
+ rf"/local/{ mapped_local_dir } /(.*)" ,
330
+ tornado .web .StaticFileHandler ,
331
+ {"path" : element .local_dir },
332
+ )
333
+ self .handlers .append (element_file_handler )
334
+ for include_file in element .local_includes :
335
+ include_file_path = f"{ mapped_local_dir } /{ include_file } "
336
+ if self ._is_stylesheet (include_file ):
337
+ self .local_css_includes .add (include_file_path )
338
+ else :
339
+ self .local_js_includes .add (include_file_path )
331
340
self .js_code .append (element .js_code )
332
341
333
342
# Initializing the model
0 commit comments