1818import plotly
1919from plotly import optional_imports , tools , utils
2020from plotly .exceptions import PlotlyError
21+ from ._plotlyjs_version import __plotlyjs_version__
2122
2223ipython = optional_imports .get_module ('IPython' )
2324ipython_display = optional_imports .get_module ('IPython.display' )
@@ -37,11 +38,66 @@ def download_plotlyjs(download_url):
3738 pass
3839
3940
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+
4053def 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+ """
4196 path = os .path .join ('package_data' , 'plotly.min.js' )
4297 plotlyjs = pkgutil .get_data ('plotly' , path ).decode ('utf-8' )
4398 return plotlyjs
4499
100+
45101def get_image_download_script (caller ):
46102 """
47103 This function will return a script that will download an image of a Plotly
0 commit comments