Skip to content

Animations/Frames in Python API #584

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 27 commits into from
Nov 26, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
cb4552c
iplot in offline works with frames
Kully Oct 18, 2016
b4c3953
updated js version in plotly offline
Kully Oct 19, 2016
54c1386
added Andrew's #586 PR
Kully Oct 20, 2016
d19c6ca
added some print statements to check progresses
Kully Oct 21, 2016
efa390e
__init__.py now accepts create_animations which lives in plotly.py --…
Kully Oct 28, 2016
eb57218
rewrote create_animations to take frames - still beta
Kully Nov 3, 2016
5482b53
merged master offline.py to local - changed call signature in one func
Kully Nov 3, 2016
b2b8451
tests
Kully Nov 3, 2016
a156503
added create_animations so v2 is hit if frames is in fig
Kully Nov 4, 2016
d173cbb
create_animations to bad_create_animations
Kully Nov 8, 2016
d17a222
added function to spit out uids from column names
Kully Nov 14, 2016
49bdc97
made get_grid() to pull grid from cloud and added method in Grid clas…
Kully Nov 15, 2016
4fbdc99
cleaned up url parsing + moved json_to_grid functionality to __init__…
Kully Nov 16, 2016
dbb386f
fixed order upon creating Grid
Kully Nov 17, 2016
bd2132b
accounted for orders with jump discontinuities
Kully Nov 18, 2016
26c3714
moved all_columns list where appropriate - above code block that uses it
Kully Nov 19, 2016
0c7bb1c
...
Kully Nov 24, 2016
4acc146
commented out fid stuff
Kully Nov 24, 2016
c195e78
merged master into branch
Kully Nov 24, 2016
6f12ba8
delete print lines from debugging
Kully Nov 24, 2016
253228f
grid_id is set to grids created via get_grid
Kully Nov 24, 2016
405e71d
add 'Frames' to grid_objs_test
Kully Nov 24, 2016
c1727d8
removed commented out code for old get_uid code
Kully Nov 24, 2016
fca8fed
added animations function
Kully Nov 24, 2016
587dfa5
Chris' comments sans tests
Kully Nov 25, 2016
495b015
changed some terminology around
Kully Nov 26, 2016
dd20177
last of non-blocking
Kully Nov 26, 2016
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
3 changes: 2 additions & 1 deletion plotly/plotly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
meta_ops,
file_ops,
get_config,
get_grid
get_grid,
create_animations
)
36 changes: 36 additions & 0 deletions plotly/plotly/plotly.py
Original file line number Diff line number Diff line change
Expand Up @@ -1493,6 +1493,42 @@ def get_grid(grid_url, raw=False):
return json_res


def create_animations(figure, filename=None, sharing='public'):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to create an i version of this that works in ipython notebooks like icreate_animations or else add it as like an output method.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should tell the user that this is a beta endpoint that is subject to deprecation in the future.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And we should describe how this is similar and dissimilar to plotly.plotly.plot. Includes things like:

  • Folders aren't supported
  • Overwrite isn't supported
  • Animations via frames are supported
  • There might be some other things that I'm forgetting about.

Put description here.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚡️


For parameter descriptions, see the doc string for `py.plot()`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of py.plot, plotly.plotly.plot since py is just an alias.

`private` is not supported currently for param 'sharing'. Returns the
url for the plot if response is ok.
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should include some basic examples of animations in here.

credentials = get_credentials()
validate_credentials(credentials)
username, api_key = credentials['username'], credentials['api_key']
auth = HTTPBasicAuth(str(username), str(api_key))
headers = {'Plotly-Client-Platform': 'python'}

json = {
'figure': figure,
'world_readable': 'true'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're JSON-ifying everything correctly in the request, then this can simply be True. You may need to add 'content-type': 'application/json' to the headers of the request

}

# set filename if specified
if filename:
json['filename'] = filename
Copy link
Member

@chriddyp chriddyp Nov 24, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In py.plot, if the user specifies a / in the filename then we'll automatically make folders for them. That won't happen here. We might want to check for / in the filename and then issue a warning to the user that this beta function won't create folders automatically for them.


# set sharing
if sharing == 'public':
json['world_readable'] = 'true'
elif sharing == 'private':
json['world_readable'] = 'false'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should add 'secret' in here. we should also throw an error if sharing isn't one of public, private, or secret


api_url = _api_v2.api_url('plots')
r = requests.post(api_url, auth=auth, headers=headers, json=json)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens when the request fails? It can fail for a number of reasons:

  • API key wasn't supplied
  • API key wasn't correct
  • User was offline
  • Request was throttled
  • Figure was malformed
  • Duplicate filename
  • Permission denied (can't save the file as private)
  • Server was down
  • And more

Errors can be detected by checking for non-200 level status codes or by calling r.raise_for_status(). Plotly returns the error in a standard format (something like {error: {message: 'error message'}} but I don't recall exactly) and we should parse the error message and then rethrow an error with that message for the user.

All of those errors should have a similar error response but you should try to hit those errors manually yourself to verify that the error handling works correctly and is helpful. Bonus points for including all of those types of errors inside actual tests so that we're sure that our error handling doesn't change without us knowing.


json_r = json.loads(r.text)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can fail if the response wasn't JSON. we might want to do

try:
    parsed_response = r.json()
except:
    parsed_response = r.content

return json_r['file']['web_url']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forget if this URL includes the title text at the end of the URL (e.g. https://plot.ly/~chris/15/my-title-of-my-graph) or not. We should make sure that we're returning the minimal version of the url like https://plot.ly/~chris/15 just like how py.plot does

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is minimal but will check



Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add tests for this function including the possible types of errors that can occur

def _open_url(url):
try:
from webbrowser import open as wbopen
Expand Down