Skip to content

first pass at nteract support #562

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Feb 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Added
- Support for rendering plots in [nteract](https://nteract.io/)!
See [https://github.com/nteract/nteract/pull/662](https://github.com/nteract/nteract/pull/662)
for the associated PR in nteract.

### Added
- `memoize` decorator added to `plotly.utils`
Expand Down
17 changes: 15 additions & 2 deletions plotly/offline/offline.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly',
validate=True, image=None, filename='plot_image', image_width=800,
image_height=600):
"""
Draw plotly graphs inside an IPython notebook without
Draw plotly graphs inside an IPython or Jupyter notebook without
connecting to an external server.
To save the chart to Plotly Cloud or Plotly Enterprise, use
`plotly.plotly.iplot`.
Expand Down Expand Up @@ -335,7 +335,20 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly',
figure_or_data, config, validate, '100%', 525, True
)

ipython_display.display(ipython_display.HTML(plot_html))
figure = tools.return_figure_from_figure_or_data(figure_or_data, validate)

# Though it can add quite a bit to the display-bundle size, we include
# multiple representations of the plot so that the display environment can
# choose which one to act on.
data = _json.loads(_json.dumps(figure['data'],
cls=plotly.utils.PlotlyJSONEncoder))
layout = _json.loads(_json.dumps(figure.get('layout', {}),
cls=plotly.utils.PlotlyJSONEncoder))
display_bundle = {
'application/vnd.plotly.v1+json': {'data': data, 'layout': layout},
'text/html': plot_html
}
ipython_display.display(display_bundle, raw=True)

if image:
if image not in __IMAGE_FORMATS:
Expand Down
6 changes: 3 additions & 3 deletions plotly/tests/test_core/test_file/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
"""
import random
import string
import requests
from unittest import TestCase

from nose.plugins.attrib import attr

import plotly.plotly as py
from plotly.exceptions import PlotlyRequestError
from plotly.tests.utils import PlotlyTestCase


@attr('slow')
class FolderAPITestCase(TestCase):
class FolderAPITestCase(PlotlyTestCase):

def setUp(self):
super(FolderAPITestCase, self).setUp()
py.sign_in('PythonTest', '9v9f20pext')

def _random_filename(self):
Expand Down
135 changes: 56 additions & 79 deletions plotly/tests/test_core/test_get_figure/test_get_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,12 @@

from unittest import TestCase, skipIf

from nose.plugins.attrib import attr
from nose.tools import raises

import six
from nose.plugins.attrib import attr

from plotly import exceptions
from plotly.graph_objs import graph_objs
from plotly.plotly import plotly as py

# username for tests: 'plotlyimagetest'
# api_key for account: '786r5mecv0'
from plotly.tests.utils import PlotlyTestCase


def is_trivial(obj):
Expand All @@ -41,75 +36,59 @@ def is_trivial(obj):
return False


@attr('slow')
def test_get_figure():
un = 'PlotlyImageTest'
ak = '786r5mecv0'
file_id = 2
py.sign_in(un, ak)
print("getting: https://plot.ly/~{0}/{1}/".format(un, file_id))
print("###########################################\n\n")
fig = py.get_figure('PlotlyImageTest', str(file_id))


@attr('slow')
def test_get_figure_with_url():
un = 'PlotlyImageTest'
ak = '786r5mecv0'
url = "https://plot.ly/~PlotlyImageTest/2/"
py.sign_in(un, ak)
print("getting: https://plot.ly/~PlotlyImageTest/2/")
print("###########################################\n\n")
fig = py.get_figure(url)


@raises(exceptions.PlotlyError)
def test_get_figure_invalid_1():
un = 'PlotlyImageTest'
ak = '786r5mecv0'
url = "https://plot.ly/~PlotlyImageTest/a/"
py.sign_in(un, ak)
print("not getting: https://plot.ly/~PlotlyImageTest/a/")
print("###########################################\n\n")
fig = py.get_figure(url)


@attr('slow')
@raises(exceptions.PlotlyError)
def test_get_figure_invalid_2():
un = 'PlotlyImageTest'
ak = '786r5mecv0'
url = "https://plot.ly/~PlotlyImageTest/-1/"
py.sign_in(un, ak)
print("not getting: https://plot.ly/~PlotlyImageTest/-1/")
print("###########################################\n\n")
fig = py.get_figure(url)


@attr('slow')
@raises(exceptions.PlotlyError)
def test_get_figure_does_not_exist():
un = 'PlotlyImageTest'
ak = '786r5mecv0'
url = "https://plot.ly/~PlotlyImageTest/1000000000/"
py.sign_in(un, ak)
print("not getting: https://plot.ly/~PlotlyImageTest/1000000000/")
print("###########################################\n\n")
fig = py.get_figure(url)


@attr('slow')
def test_get_figure_raw():
un = 'PlotlyImageTest'
ak = '786r5mecv0'
file_id = 2
py.sign_in(un, ak)
print("getting: https://plot.ly/~{0}/{1}/".format(un, file_id))
print("###########################################\n\n")
fig = py.get_figure('PlotlyImageTest', str(file_id), raw=True)


@attr('slow')
class GetFigureTest(PlotlyTestCase):

@attr('slow')
def test_get_figure(self):
un = 'PlotlyImageTest'
ak = '786r5mecv0'
file_id = 2
py.sign_in(un, ak)
py.get_figure('PlotlyImageTest', str(file_id))

@attr('slow')
def test_get_figure_with_url(self):
un = 'PlotlyImageTest'
ak = '786r5mecv0'
url = "https://plot.ly/~PlotlyImageTest/2/"
py.sign_in(un, ak)
py.get_figure(url)

def test_get_figure_invalid_1(self):
un = 'PlotlyImageTest'
ak = '786r5mecv0'
url = "https://plot.ly/~PlotlyImageTest/a/"
py.sign_in(un, ak)
with self.assertRaises(exceptions.PlotlyError):
py.get_figure(url)

@attr('slow')
def test_get_figure_invalid_2(self):
un = 'PlotlyImageTest'
ak = '786r5mecv0'
url = "https://plot.ly/~PlotlyImageTest/-1/"
py.sign_in(un, ak)
with self.assertRaises(exceptions.PlotlyError):
py.get_figure(url)

@attr('slow')
def test_get_figure_does_not_exist(self):
un = 'PlotlyImageTest'
ak = '786r5mecv0'
url = "https://plot.ly/~PlotlyImageTest/1000000000/"
py.sign_in(un, ak)
with self.assertRaises(exceptions.PlotlyError):
py.get_figure(url)

@attr('slow')
def test_get_figure_raw(self):
un = 'PlotlyImageTest'
ak = '786r5mecv0'
file_id = 2
py.sign_in(un, ak)
py.get_figure('PlotlyImageTest', str(file_id), raw=True)


class TestBytesVStrings(TestCase):

@skipIf(not six.PY3, 'Decoding and missing escapes only seen in PY3')
Expand All @@ -118,6 +97,4 @@ def test_proper_escaping(self):
ak = '786r5mecv0'
url = "https://plot.ly/~PlotlyImageTest/91/"
py.sign_in(un, ak)
print("getting: https://plot.ly/~PlotlyImageTest/91/")
print("###########################################\n\n")
fig = py.get_figure(url)
py.get_figure(url)
Loading