@@ -122,52 +122,26 @@ def _plot_html(figure_or_data, show_link, link_text,
122
122
config = jconfig )
123
123
124
124
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
141
126
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
157
130
158
- return plotly_html_div , plotdivid , width , height
131
+ optional_line1 = 'require(["plotly"], function(Plotly) {{ ' if nb else ''
132
+ optional_line2 = '}});' if nb else ''
159
133
160
134
plotly_html_div = (
161
135
''
162
136
'<div id="{id}" style="height: {height}; width: {width};" '
163
137
'class="plotly-graph-div">'
164
138
'</div>'
165
- '<script type="text/javascript">'
166
- 'require(["plotly"], function(Plotly) {{'
139
+ '<script type="text/javascript">' +
140
+ optional_line1 +
167
141
'window.PLOTLYENV=window.PLOTLYENV || {{}};'
168
142
'window.PLOTLYENV.BASE_URL="' + plotly_platform_url + '";'
169
- '{script}'
170
- '}});'
143
+ '{script}' +
144
+ optional_line2 +
171
145
'</script>'
172
146
'' ).format (
173
147
id = plotdivid , script = script ,
0 commit comments