MCPcopy Index your code
hub / github.com/plotly/plotly.py / get_plotlyjs

Function get_plotlyjs

plotly/offline/offline.py:42–87  ·  view source on GitHub ↗

Return the contents of the minified plotly.js library as a string. This may be useful when building standalone HTML reports. Returns ------- str Contents of the minified plotly.js library as a string Examples -------- Here is an example of creating a stand

()

Source from the content-addressed store, hash-verified

40
41
42def get_plotlyjs():
43 """
44 Return the contents of the minified plotly.js library as a string.
45
46 This may be useful when building standalone HTML reports.
47
48 Returns
49 -------
50 str
51 Contents of the minified plotly.js library as a string
52
53 Examples
54 --------
55 Here is an example of creating a standalone HTML report that contains
56 two plotly figures, each in their own div. The include_plotlyjs argument
57 is set to False when creating the divs so that we don't include multiple
58 copies of the plotly.js library in the output. Instead, a single copy
59 of plotly.js is included in a script tag in the html head element.
60
61 >>> import plotly.graph_objs as go
62 >>> from plotly.offline import plot, get_plotlyjs
63 >>> fig1 = go.Figure(data=[{'type': 'bar', 'y': [1, 3, 2]}],
64 ... layout={'height': 400})
65 >>> fig2 = go.Figure(data=[{'type': 'scatter', 'y': [1, 3, 2]}],
66 ... layout={'height': 400})
67 >>> div1 = plot(fig1, output_type='div', include_plotlyjs=False)
68 >>> div2 = plot(fig2, output_type='div', include_plotlyjs=False)
69
70 >>> html = '''
71 ... <html>
72 ... <head>
73 ... <script>{plotlyjs}</script>
74 ... </head>
75 ... <body>
76 ... {div1}
77 ... {div2}
78 ... </body>
79 ... </html>
80 ... ''&#x27;.format(plotlyjs=get_plotlyjs(), div1=div1, div2=div2)
81
82 >>> with open('multi_plot.html', 'w') as f:
83 ... f.write(html) # doctest: +SKIP
84 """
85 path = os.path.join("package_data", "plotly.min.js")
86 plotlyjs = pkgutil.get_data("plotly", path).decode("utf-8")
87 return plotlyjs
88
89
90def _build_resize_script(plotdivid, plotly_root="Plotly"):

Callers 7

to_htmlFunction · 0.90
write_htmlFunction · 0.90
activateMethod · 0.90
test_offline.pyFile · 0.90
assert_offlineFunction · 0.90
test_repr_htmlFunction · 0.90

Calls 1

decodeMethod · 0.45

Tested by 3

assert_offlineFunction · 0.72
test_repr_htmlFunction · 0.72