@@ -42,10 +42,12 @@ def download_plotlyjs(download_url):
42
42
pass
43
43
44
44
45
- def get_plotlyjs ():
46
- # path = os.path.join('offline', 'plotly.min.js')
47
- # plotlyjs = resource_string('plotly', path).decode('utf-8')
48
- plotlyjs = '</script><script src="plotly.min.js">'
45
+ def get_plotlyjs ( outsource_plotly = False ):
46
+ if outsource_plotly :
47
+ plotlyjs = '</script><script src="plotly.min.js">'
48
+ else :
49
+ path = os .path .join ('offline' , 'plotly.min.js' )
50
+ plotlyjs = resource_string ('plotly' , path ).decode ('utf-8' )
49
51
return plotlyjs
50
52
51
53
@@ -244,7 +246,8 @@ def plot(figure_or_data,
244
246
validate = True , output_type = 'file' ,
245
247
include_plotlyjs = True ,
246
248
filename = 'temp-plot.html' ,
247
- auto_open = True ):
249
+ auto_open = True ,
250
+ outsource_plotly = False ):
248
251
""" Create a plotly graph locally as an HTML document or string.
249
252
250
253
Example:
@@ -290,6 +293,10 @@ def plot(figure_or_data,
290
293
auto_open (default=True) -- If True, open the saved file in a
291
294
web browser after saving.
292
295
This argument only applies if `output_type` is 'file'.
296
+ outsource_plotly (default=False) -- If True, the javascript library will
297
+ be copied into a separate file, thereby reducing the file size for the
298
+ actual plat significantly. This is handy if several plots are created
299
+ in the same folder.
293
300
"""
294
301
if output_type not in ['div' , 'file' ]:
295
302
raise ValueError (
@@ -329,7 +336,7 @@ def plot(figure_or_data,
329
336
if include_plotlyjs :
330
337
plotly_js_script = '' .join ([
331
338
'<script type="text/javascript">' ,
332
- get_plotlyjs (),
339
+ get_plotlyjs (outsource_plotly = outsource_plotly ),
333
340
'</script>' ,
334
341
])
335
342
else :
@@ -356,7 +363,7 @@ def plot(figure_or_data,
356
363
return '' .join ([
357
364
'<div>' ,
358
365
'<script type="text/javascript">' ,
359
- get_plotlyjs (),
366
+ get_plotlyjs (outsource_plotly = outsource_plotly ),
360
367
'</script>' ,
361
368
plot_html ,
362
369
'</div>'
0 commit comments