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
2 changes: 2 additions & 0 deletions plotly/graph_objs/graph_objs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Copy link
Contributor

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 into Figure? As always, pls put the issue numer (or link) in the TODO comment.

super(PlotlyDict, self).__setitem__(key, value)
Expand All @@ -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:
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Expand Down
40 changes: 21 additions & 19 deletions plotly/offline/offline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

TODO this and link to some issue pls :)

# TODO - add validation for frames in call - #
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
Expand Down Expand Up @@ -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)

Expand Down
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,
bad_create_animations
bad_create_animations,
get_uid_by_col_name
)
40 changes: 36 additions & 4 deletions plotly/plotly/plotly.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -939,6 +939,7 @@ def upload(cls, grid, filename,

paths = filename.split('/')
parent_path = '/'.join(paths[0:-1])

filename = paths[-1]

if parent_path != '':
Expand All @@ -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'])
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -1576,6 +1575,39 @@ def bad_create_animations(fig, kwargs, payload):
return r_dict


def get_uid_by_col_name(grid_url, col_name):
Copy link
Contributor

Choose a reason for hiding this comment

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

The grid_url arg should be a little more flexible. Look at https://github.com/plotly/plotly.py/blob/master/plotly/plotly/plotly.py#L318. I'm OK with this as is. But I could see it being frustrating to be able to reference files one way in one place and another way in another place.

Copy link
Contributor

Choose a reason for hiding this comment

The 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 Grid class? More like:

1. Get `Grid` from `grid_url` (symmetric to `get_figure`), this is a network operation
2. Get `uid` from `Grid` (which is a simple, local operation)

"""
Search for a column of a grid by name and return the uid of the column.
"""
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)
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


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