@@ -94,7 +94,7 @@ def ensure_local_plotly_files_exist():
94
94
95
95
### credentials tools ###
96
96
97
- def set_credentials_file (username = "" , api_key = "" , stream_ids = ()):
97
+ def set_credentials_file (username = "" , api_key = "" , stream_ids = (), ** extra ):
98
98
"""Set the keyword-value pairs in `~/.plotly_credentials`.
99
99
100
100
"""
@@ -108,6 +108,7 @@ def set_credentials_file(username="", api_key="", stream_ids=()):
108
108
credentials ['api_key' ] = api_key
109
109
if stream_ids :
110
110
credentials ['stream_ids' ] = stream_ids
111
+ credentials .update (extra )
111
112
utils .save_json (CREDENTIALS_FILE , credentials )
112
113
113
114
@@ -144,23 +145,26 @@ def show_credentials_file(*args):
144
145
145
146
def get_embed (username , plot_id , width = "100%" , height = 525 ):
146
147
padding = 25
148
+ plotly_rest_url = _get_plotly_urls ()[0 ]
147
149
if isinstance (width , (int , long )):
148
150
s = ("<iframe id=\" igraph\" scrolling=\" no\" style=\" border:none;\" "
149
151
"seamless=\" seamless\" "
150
- "src=\" https://plot.ly /"
152
+ "src=\" {plotly_rest_url} /"
151
153
"~{username}/{plot_id}/{plot_width}/{plot_height}\" "
152
154
"height=\" {iframe_height}\" width=\" {iframe_width}\" >"
153
155
"</iframe>" ).format (
156
+ plotly_rest_url = plotly_rest_url ,
154
157
username = username , plot_id = plot_id ,
155
158
plot_width = width - padding , plot_height = height - padding ,
156
159
iframe_height = height , iframe_width = width )
157
160
else :
158
161
s = ("<iframe id=\" igraph\" scrolling=\" no\" style=\" border:none;\" "
159
162
"seamless=\" seamless\" "
160
- "src=\" https://plot.ly /"
163
+ "src=\" {plotly_rest_url} /"
161
164
"~{username}/{plot_id}\" "
162
165
"height=\" {iframe_height}\" width=\" {iframe_width}\" >"
163
166
"</iframe>" ).format (
167
+ plotly_rest_url = plotly_rest_url ,
164
168
username = username , plot_id = plot_id ,
165
169
iframe_height = height , iframe_width = width )
166
170
@@ -369,7 +373,7 @@ def validate_stream(obj, obj_type):
369
373
"""Validate a data dictionary (only) for use with streaming.
370
374
371
375
An error is raised if a key within (or nested within) is not streamable.
372
-
376
+
373
377
"""
374
378
try :
375
379
obj_type = graph_objs .KEY_TO_NAME [obj_type ]
@@ -396,4 +400,27 @@ def validate_stream(obj, obj_type):
396
400
sub_obj_type = graph_objs .KEY_TO_NAME [key ]
397
401
validate_stream (val , sub_obj_type )
398
402
except KeyError :
399
- pass
403
+ pass
404
+
405
+ def _get_plotly_urls ():
406
+ ''' Return url endpoints for Plotly services.
407
+ These endpoints are configurable, and are
408
+ retrieved from ~/.plotly/.credentials as:
409
+ {
410
+ 'plotly_rest_url': '...',
411
+ 'plotly_streaming_url': '...'
412
+ }
413
+ '''
414
+ config_on_file = get_credentials_file ()
415
+
416
+ if 'plotly_rest_url' in config_on_file :
417
+ plotly_rest_url = config_on_file ['plotly_rest_url' ]
418
+ else :
419
+ plotly_rest_url = 'https://plot.ly'
420
+
421
+ if 'plotly_streaming_url' in config_on_file :
422
+ plotly_streaming_url = config_on_file ['plotly_streaming_url' ]
423
+ else :
424
+ plotly_streaming_url = 'stream.plot.ly'
425
+
426
+ return (plotly_rest_url , plotly_streaming_url )
0 commit comments