18
18
import plotly
19
19
from plotly import optional_imports , tools , utils
20
20
from plotly .exceptions import PlotlyError
21
+ from ._plotlyjs_version import __plotlyjs_version__
21
22
22
23
ipython = optional_imports .get_module ('IPython' )
23
24
ipython_display = optional_imports .get_module ('IPython.display' )
@@ -37,11 +38,66 @@ def download_plotlyjs(download_url):
37
38
pass
38
39
39
40
41
+ def get_plotlyjs_version ():
42
+ """
43
+ Returns the version of plotly.js that is bundled with plotly.py.
44
+
45
+ Returns
46
+ -------
47
+ str
48
+ Plotly.js version string
49
+ """
50
+ return __plotlyjs_version__
51
+
52
+
40
53
def get_plotlyjs ():
54
+ """
55
+ Return the contents of the minified plotly.js library as a string.
56
+
57
+ This may be useful when building standalone HTML reports.
58
+
59
+ Returns
60
+ -------
61
+ str
62
+ Contents of the minified plotly.js library as a string
63
+
64
+ Examples
65
+ --------
66
+ Here is an example of creating a standalone HTML report that contains
67
+ two plotly figures, each in their own div. The include_plotlyjs argument
68
+ is set to False when creating the divs so that we don't include multiple
69
+ copies of the plotly.js library in the output. Instead, a single copy
70
+ of plotly.js is included in a script tag in the html head element.
71
+
72
+ >>> import plotly.graph_objs as go
73
+ >>> from plotly.offline import plot, get_plotlyjs
74
+ >>> fig1 = go.Figure(data=[{'type': 'bar', 'y': [1, 3, 2]}],
75
+ ... layout={'height': 400})
76
+ >>> fig2 = go.Figure(data=[{'type': 'scatter', 'y': [1, 3, 2]}],
77
+ ... layout={'height': 400})
78
+ >>> div1 = plot(fig1, output_type='div', include_plotlyjs=False)
79
+ >>> div2 = plot(fig2, output_type='div', include_plotlyjs=False)
80
+
81
+ >>> html = '''
82
+ ... <html>
83
+ ... <head>
84
+ ... <script type="text/javascript">{plotlyjs}</script>
85
+ ... </head>
86
+ ... <body>
87
+ ... {div1}
88
+ ... {div2}
89
+ ... </body>
90
+ ... </html>
91
+ ...'''.format(plotlyjs=get_plotlyjs(), div1=div1, div2=div2)
92
+
93
+ >>> with open('multi_plot.html', 'w') as f:
94
+ ... f.write(html)
95
+ """
41
96
path = os .path .join ('package_data' , 'plotly.min.js' )
42
97
plotlyjs = pkgutil .get_data ('plotly' , path ).decode ('utf-8' )
43
98
return plotlyjs
44
99
100
+
45
101
def get_image_download_script (caller ):
46
102
"""
47
103
This function will return a script that will download an image of a Plotly
0 commit comments