-
-
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 |
---|---|---|
|
@@ -836,6 +836,7 @@ def __init__(self, *args, **kwargs): | |
_parent_key='data') | ||
figure_class.__init__ = __init__ | ||
|
||
# TODO better integrate frames into Figure - #604 | ||
def __setitem__(self, key, value, **kwargs): | ||
if key == 'frames': | ||
super(PlotlyDict, self).__setitem__(key, value) | ||
|
@@ -845,6 +846,7 @@ def __setitem__(self, key, value, **kwargs): | |
|
||
def _get_valid_attributes(self): | ||
super(figure_class, self)._get_valid_attributes() | ||
# TODO better integrate frames into Figure - #604 | ||
if 'frames' not in self._valid_attributes: | ||
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. Ditto hear, link it to that same issue ^^ |
||
self._valid_attributes.add('frames') | ||
return self._valid_attributes | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,6 +163,7 @@ def init_notebook_mode(connected=False): | |
def _plot_html(figure_or_data, config, validate, default_width, | ||
default_height, global_requirejs): | ||
# force no validation if frames is in the call | ||
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.
|
||
# TODO - add validation for frames in call - # | ||
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. Thanks for linking issues ❤️! Looks like this one may have been missed though. 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. LOL, whoops! That's #605 |
||
if 'frames' in figure_or_data: | ||
figure = tools.return_figure_from_figure_or_data( | ||
figure_or_data, False | ||
|
@@ -196,25 +197,26 @@ def _plot_html(figure_or_data, config, validate, default_width, | |
jframes = json.dumps(figure.get('frames', {}), cls=utils.PlotlyJSONEncoder) | ||
|
||
configkeys = ( | ||
'editable', | ||
'autosizable', | ||
'fillFrame', | ||
'frameMargins', | ||
'scrollZoom', | ||
'doubleClick', | ||
'showTips', | ||
'showLink', | ||
'sendData', | ||
'linkText', | ||
'showSources', | ||
'displayModeBar', | ||
'modeBarButtonsToRemove', | ||
'modeBarButtonsToAdd', | ||
'modeBarButtons', | ||
'displaylogo', | ||
'plotGlPixelRatio', | ||
'setBackground', | ||
'topojsonURL') | ||
'editable', | ||
'autosizable', | ||
'fillFrame', | ||
'frameMargins', | ||
'scrollZoom', | ||
'doubleClick', | ||
'showTips', | ||
'showLink', | ||
'sendData', | ||
'linkText', | ||
'showSources', | ||
'displayModeBar', | ||
'modeBarButtonsToRemove', | ||
'modeBarButtonsToAdd', | ||
'modeBarButtons', | ||
'displaylogo', | ||
'plotGlPixelRatio', | ||
'setBackground', | ||
'topojsonURL' | ||
) | ||
|
||
config_clean = dict((k,config[k]) for k in configkeys if k in config) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,5 +22,6 @@ | |
meta_ops, | ||
file_ops, | ||
get_config, | ||
bad_create_animations | ||
bad_create_animations, | ||
get_uid_by_col_name | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -499,7 +499,7 @@ def heartbeat(self, reconnect_on=(200, '', 408)): | |
"cannot write to a closed connection. " | ||
"Call `open()` on the stream to open the stream." | ||
) | ||
|
||
@property | ||
def connected(self): | ||
if self._stream is None: | ||
|
@@ -939,6 +939,7 @@ def upload(cls, grid, filename, | |
|
||
paths = filename.split('/') | ||
parent_path = '/'.join(paths[0:-1]) | ||
|
||
filename = paths[-1] | ||
|
||
if parent_path != '': | ||
|
@@ -959,6 +960,7 @@ def upload(cls, grid, filename, | |
payload['parent_path'] = parent_path | ||
|
||
upload_url = _api_v2.api_url('grids') | ||
|
||
req = requests.post(upload_url, data=payload, | ||
headers=_api_v2.headers(), | ||
verify=get_config()['plotly_ssl_verification']) | ||
|
@@ -1423,9 +1425,6 @@ def _send_to_plotly(figure, **plot_options): | |
origin='plot', | ||
kwargs=kwargs) | ||
|
||
#if 'frames' in fig: | ||
# r = create_animations(fig, kwargs, payload) | ||
#else: | ||
url = get_config()['plotly_domain'] + "/clientresp" | ||
|
||
r = requests.post(url, data=payload, | ||
|
@@ -1576,6 +1575,39 @@ def bad_create_animations(fig, kwargs, payload): | |
return r_dict | ||
|
||
|
||
def get_uid_by_col_name(grid_url, col_name): | ||
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. The 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. Also. I sort of imagined that this would have been part of our
|
||
""" | ||
Search for a column of a grid by name and return the uid of the column. | ||
""" | ||
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) | ||
auth = HTTPBasicAuth(credentials['username'], credentials['api_key']) | ||
headers = {'Plotly-Client-Platform': 'python'} | ||
upload_url = _api_v2.api_url('grids') | ||
|
||
tilda_index = grid_url.find('~') | ||
fid_in_url = grid_url[tilda_index + 1: -1].replace('/', ':') | ||
get_url = upload_url + '/' + fid_in_url | ||
|
||
r = requests.get(get_url, auth=auth, headers=headers) | ||
r_text = json.loads(r.text) | ||
|
||
col_uid = '' | ||
for col in r_text['cols']: | ||
if col_name == col['name']: | ||
col_uid = col['uid'] | ||
break | ||
|
||
all_col_names = ([r_text['cols'][j]['name'] for j in | ||
range(len(r_text['cols']))]) | ||
if col_uid == '': | ||
raise exceptions.PlotlyError( | ||
'The col_name does not match with any column name in your grid. ' | ||
'The column names in your grid are {}'.format(all_col_names)) | ||
else: | ||
return col_uid | ||
|
||
|
||
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.
Let's add a comment about this one. Maybe tie it to a new issue to better-integrate
frames
intoFigure
? As always, pls put the issue numer (or link) in theTODO
comment.