Skip to content

Commit 584b627

Browse files
committed
Merge pull request #146 from plotly/embed-width-height
Fix IPython NB embed with custom width & height
2 parents 31d55dc + 346df62 commit 584b627

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

plotly/tools.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,8 @@ def get_embed(file_owner_or_url, file_id=None, width="100%", height=525):
248248
s = ("<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\""
249249
"seamless=\"seamless\" "
250250
"src=\"{plotly_rest_url}/"
251-
"~{file_owner}/{file_id}/{plot_width}/{plot_height}\" "
251+
"~{file_owner}/{file_id}.embed"
252+
"?width={plot_width}&height={plot_height}\" "
252253
"height=\"{iframe_height}\" width=\"{iframe_width}\">"
253254
"</iframe>").format(
254255
plotly_rest_url=plotly_rest_url,
@@ -259,7 +260,7 @@ def get_embed(file_owner_or_url, file_id=None, width="100%", height=525):
259260
s = ("<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\""
260261
"seamless=\"seamless\" "
261262
"src=\"{plotly_rest_url}/"
262-
"~{file_owner}/{file_id}\" "
263+
"~{file_owner}/{file_id}.embed\" "
263264
"height=\"{iframe_height}\" width=\"{iframe_width}\">"
264265
"</iframe>").format(
265266
plotly_rest_url=plotly_rest_url,
@@ -291,8 +292,8 @@ def embed(file_owner_or_url, file_id=None, width="100%", height=525):
291292
height (default="525") -- same as width but corresp. to the height of the figure
292293
293294
"""
294-
s = get_embed(file_owner_or_url, file_id, width, height)
295295
try:
296+
s = get_embed(file_owner_or_url, file_id, width, height)
296297
# see if we are in the SageMath Cloud
297298
from sage_salvus import html
298299
return html(s, hide=False)
@@ -306,7 +307,7 @@ def embed(file_owner_or_url, file_id=None, width="100%", height=525):
306307
fid=file_id)
307308
else:
308309
url = file_owner_or_url
309-
return PlotlyDisplay(url)
310+
return PlotlyDisplay(url, width, height)
310311
else:
311312
warnings.warn(
312313
"Looks like you're not using IPython or Sage to embed this plot. "
@@ -571,11 +572,14 @@ class PlotlyDisplay(IPython.core.display.HTML):
571572
object can provide alternate representations.
572573
573574
"""
574-
def __init__(self, url):
575+
def __init__(self, url, width, height):
575576
self.resource = url
576-
self.embed_code = get_embed(url)
577+
self.embed_code = get_embed(url, width=width, height=height)
577578
super(PlotlyDisplay, self).__init__(data=self.embed_code)
578579

580+
def _repr_html_(self):
581+
return self.embed_code
582+
579583
def _repr_svg_(self):
580584
url = self.resource + ".svg"
581585
res = requests.get(url)

plotly/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.4.4'
1+
__version__ = '1.4.5'

0 commit comments

Comments
 (0)