Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1b2d712

Browse filesBrowse files
committed
shorter code
1 parent c342abf commit 1b2d712
Copy full SHA for 1b2d712

File tree

1 file changed

+10
-36
lines changed
Filter options

1 file changed

+10
-36
lines changed

‎plotly/offline/offline.py

Copy file name to clipboardExpand all lines: plotly/offline/offline.py
+10-36Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -122,52 +122,26 @@ def _plot_html(figure_or_data, show_link, link_text,
122122
config=jconfig)
123123

124124
if kwargs and kwargs['browser']:
125-
plotly_html_div = (
126-
''
127-
'<div id="{id}" style="height: {height}; width: {width};" '
128-
'class="plotly-graph-div">'
129-
'</div>'
130-
'<script type="text/javascript">'
131-
'window.PLOTLYENV=window.PLOTLYENV || {{}};'
132-
'window.PLOTLYENV.BASE_URL="' + plotly_platform_url + '";'
133-
'{script}'
134-
'</script>'
135-
'').format(
136-
id=plotdivid, script=script,
137-
height=height, width=width)
138-
139-
return plotly_html_div, plotdivid, width, height
140-
125+
nb = False # function was not called from a notebook
141126
else:
142-
plotly_html_div = (
143-
''
144-
'<div id="{id}" style="height: {height}; width: {width};" '
145-
'class="plotly-graph-div">'
146-
'</div>'
147-
'<script type="text/javascript">'
148-
'require(["plotly"], function(Plotly) {{'
149-
'window.PLOTLYENV=window.PLOTLYENV || {{}};'
150-
'window.PLOTLYENV.BASE_URL="' + plotly_platform_url + '";'
151-
'{script}'
152-
'}});'
153-
'</script>'
154-
'').format(
155-
id=plotdivid, script=script,
156-
height=height, width=width)
127+
nb = True
128+
129+
# evaluate whether or not to include lines based on the nb
157130

158-
return plotly_html_div, plotdivid, width, height
131+
optional_line1 = 'require(["plotly"], function(Plotly) {{ ' if nb else ''
132+
optional_line2 = '}});' if nb else ''
159133

160134
plotly_html_div = (
161135
''
162136
'<div id="{id}" style="height: {height}; width: {width};" '
163137
'class="plotly-graph-div">'
164138
'</div>'
165-
'<script type="text/javascript">'
166-
'require(["plotly"], function(Plotly) {{'
139+
'<script type="text/javascript">' +
140+
optional_line1 +
167141
'window.PLOTLYENV=window.PLOTLYENV || {{}};'
168142
'window.PLOTLYENV.BASE_URL="' + plotly_platform_url + '";'
169-
'{script}'
170-
'}});'
143+
'{script}' +
144+
optional_line2 +
171145
'</script>'
172146
'').format(
173147
id=plotdivid, script=script,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.