-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Changes from 1 commit
cb4552c
b4c3953
54c1386
d19c6ca
efa390e
eb57218
5482b53
b2b8451
a156503
d173cbb
d17a222
49bdc97
4fbdc99
dbb386f
bd2132b
26c3714
0c7bb1c
4acc146
c195e78
6f12ba8
253228f
405e71d
c1727d8
fca8fed
587dfa5
495b015
dd20177
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,5 +22,6 @@ | |
meta_ops, | ||
file_ops, | ||
get_config, | ||
get_grid | ||
get_grid, | ||
create_animations | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1493,6 +1493,42 @@ def get_grid(grid_url, raw=False): | |
return json_res | ||
|
||
|
||
def create_animations(figure, filename=None, sharing='public'): | ||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should tell the user that this is a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And we should describe how this is similar and dissimilar to
|
||
Put description here. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⚡️ |
||
|
||
For parameter descriptions, see the doc string for `py.plot()`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of |
||
`private` is not supported currently for param 'sharing'. Returns the | ||
url for the plot if response is ok. | ||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
} | ||
|
||
# set filename if specified | ||
if filename: | ||
json['filename'] = filename | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In |
||
|
||
# set sharing | ||
if sharing == 'public': | ||
json['world_readable'] = 'true' | ||
elif sharing == 'private': | ||
json['world_readable'] = 'false' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should add |
||
|
||
api_url = _api_v2.api_url('plots') | ||
r = requests.post(api_url, auth=auth, headers=headers, json=json) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
Errors can be detected by checking for non- 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||
return json_r['file']['web_url'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is minimal but will check |
||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
There was a problem hiding this comment.
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 likeicreate_animations
or else add it as like an output method.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍