@@ -152,8 +152,6 @@ def to_html(
152152 # Set responsive
153153 config .setdefault ("responsive" , True )
154154
155- jconfig = json .dumps (config )
156-
157155 # Get div width/height
158156 layout_dict = fig_dict .get ("layout" , {})
159157 template_dict = fig_dict .get ("layout" , {}).get ("template" , {}).get ("layout" , {})
@@ -177,7 +175,22 @@ def to_html(
177175 div_height = str (div_height ) + "px"
178176
179177 # ## 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 = ""
181194
182195 # ## Build script body ##
183196 # This is the part that actually calls Plotly.js
@@ -214,6 +227,9 @@ def to_html(
214227 id = plotdivid , animation_opts = animation_opts_arg
215228 )
216229
230+ # Serialize config dict to JSON
231+ jconfig = json .dumps (config )
232+
217233 script = """
218234 if (document.getElementById("{id}")) {{
219235 Plotly.newPlot(
@@ -331,8 +347,7 @@ def to_html(
331347 style="height:{height}; width:{width};"></div>
332348 <script type="text/javascript">
333349 {require_start}
334- window.PLOTLYENV=window.PLOTLYENV || {{}};
335- window.PLOTLYENV.BASE_URL='{plotly_platform_url}';
350+ window.PLOTLYENV=window.PLOTLYENV || {{}};{base_url_line}
336351 {script};
337352 {require_end}
338353 </script>
@@ -342,7 +357,7 @@ def to_html(
342357 id = plotdivid ,
343358 width = div_width ,
344359 height = div_height ,
345- plotly_platform_url = plotly_platform_url ,
360+ base_url_line = base_url_line ,
346361 require_start = require_start ,
347362 script = script ,
348363 require_end = require_end ,
0 commit comments