@@ -152,8 +152,6 @@ def to_html(
152
152
# Set responsive
153
153
config .setdefault ("responsive" , True )
154
154
155
- jconfig = json .dumps (config )
156
-
157
155
# Get div width/height
158
156
layout_dict = fig_dict .get ("layout" , {})
159
157
template_dict = fig_dict .get ("layout" , {}).get ("template" , {}).get ("layout" , {})
@@ -177,7 +175,22 @@ def to_html(
177
175
div_height = str (div_height ) + "px"
178
176
179
177
# ## Get platform URL ##
180
- plotly_platform_url = config .get ("plotlyServerURL" , "https://plot.ly" )
178
+ if config .get ("showLink" , False ) or config .get ("showSendToCloud" , False ):
179
+ # Figure is going to include a Chart Studio link or send-to-cloud button,
180
+ # So we need to configure the PLOTLYENV.BASE_URL property
181
+ base_url_line = """
182
+ window.PLOTLYENV.BASE_URL='{plotly_platform_url}';\
183
+ """ .format (
184
+ plotly_platform_url = config .get ("plotlyServerURL" , "https://plot.ly" )
185
+ )
186
+ else :
187
+ # Figure is not going to include a Chart Studio link or send-to-cloud button,
188
+ # In this case we don't want https://plot.ly to show up anywhere in the HTML
189
+ # output
190
+ config .pop ("plotlyServerURL" , None )
191
+ config .pop ("linkText" , None )
192
+ config .pop ("showLink" , None )
193
+ base_url_line = ""
181
194
182
195
# ## Build script body ##
183
196
# This is the part that actually calls Plotly.js
@@ -214,6 +227,9 @@ def to_html(
214
227
id = plotdivid , animation_opts = animation_opts_arg
215
228
)
216
229
230
+ # Serialize config dict to JSON
231
+ jconfig = json .dumps (config )
232
+
217
233
script = """
218
234
if (document.getElementById("{id}")) {{
219
235
Plotly.newPlot(
@@ -331,8 +347,7 @@ def to_html(
331
347
style="height:{height}; width:{width};"></div>
332
348
<script type="text/javascript">
333
349
{require_start}
334
- window.PLOTLYENV=window.PLOTLYENV || {{}};
335
- window.PLOTLYENV.BASE_URL='{plotly_platform_url}';
350
+ window.PLOTLYENV=window.PLOTLYENV || {{}};{base_url_line}
336
351
{script};
337
352
{require_end}
338
353
</script>
@@ -342,7 +357,7 @@ def to_html(
342
357
id = plotdivid ,
343
358
width = div_width ,
344
359
height = div_height ,
345
- plotly_platform_url = plotly_platform_url ,
360
+ base_url_line = base_url_line ,
346
361
require_start = require_start ,
347
362
script = script ,
348
363
require_end = require_end ,
0 commit comments