Skip to content

Presentations wrapper #739

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 53 commits into from
Oct 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
1bdbd00
spectacle presentations v2 added
Kully Mar 21, 2017
0f9a68c
added presentation folder w/ init file
Kully Apr 21, 2017
1bb5ec0
start working on __init__ and main presentation_objs file
Kully Apr 21, 2017
f696f5a
add some templates to the file
Kully Apr 23, 2017
6b7a24b
functional presentation_objs class and tools for uploading in plotly.…
Kully May 3, 2017
43d6dfb
Merge branch 'master' into presentations-wrapper
Kully May 3, 2017
9f9e419
fully working
Kully May 22, 2017
867a5ea
fixed language typo
Kully May 30, 2017
de91e8c
a pull
Kully May 30, 2017
16fca75
committed
Kully May 30, 2017
c590166
fully functional presentation wrapper
Kully May 31, 2017
810458c
starting an easier approach
Kully Jun 1, 2017
787fa47
more work
Kully Jun 2, 2017
a860bf5
pres work
Kully Jun 15, 2017
1682e84
added tiling on left and right
Kully Jun 20, 2017
f8e8d25
USE NON SIMPLE CODE FROM HERE
Kully Jun 24, 2017
8988984
fixed tiled bug
Kully Jun 26, 2017
9db2ae0
stuff
Kully Jun 27, 2017
4032836
remove print text_lines
Kully Jun 27, 2017
1f3c65a
merge conflicts for pres-wrapper file
Kully Sep 12, 2017
91872e4
comment about inserting plotly elements to presentation
Kully Sep 21, 2017
ed51410
...
Kully Sep 21, 2017
fe87242
more hammering away
Kully Sep 26, 2017
0c5ed79
setting up martik
Kully Oct 2, 2017
4a95b56
matrik done
Kully Oct 3, 2017
7dd4312
more prep work
Kully Oct 3, 2017
9161285
martik colors
Kully Oct 4, 2017
8f5a22a
fixed code_blocks code_index bug
Kully Oct 10, 2017
2e13abf
moods complete
Kully Oct 11, 2017
5445e0d
merging from master
Kully Oct 11, 2017
3a4dc4a
...
Kully Oct 11, 2017
1a5d401
add tests
Kully Oct 11, 2017
26fca4e
full tests
Kully Oct 12, 2017
ab843de
PEP-8
Kully Oct 12, 2017
6d02718
fixed python 3 syntax errors
Kully Oct 12, 2017
46cc8a5
pep-8
Kully Oct 13, 2017
50795b9
added word 'online' to presentations_ops doc string
Kully Oct 13, 2017
773054d
changing url to plotly and image
Kully Oct 18, 2017
3f6a0b6
paragraph styles now update
Kully Oct 19, 2017
7121495
added doc string to Presentation
Kully Oct 20, 2017
eba5a1f
fixed upload function for pres
Kully Oct 20, 2017
d610943
fixed tests and added
Kully Oct 20, 2017
c5e95c4
make default schema
Kully Oct 20, 2017
06bb679
changelog and version bump
Kully Oct 20, 2017
c8d731e
part of chris' comments
Kully Oct 24, 2017
1a72c5a
comment style out - minor
Kully Oct 24, 2017
52117e5
more commenting out
Kully Oct 24, 2017
fad18aa
commenting again
Kully Oct 25, 2017
d38fbf3
bug fixed - added position:absolute in text styles
Kully Oct 25, 2017
db1a9ff
more chris comments and change middle 3 slide title 'top' pos
Kully Oct 25, 2017
abb4178
all tests but final are ready
Kully Oct 25, 2017
43ae1d0
finished tests and added comment for 512 height, width defaults
Kully Oct 25, 2017
f9424c2
make default schema
Kully Oct 25, 2017
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 @@ -2,6 +2,10 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [2.2.0] - 2017-10-20
### Added
- NEW Presentations API for Python! Run `help(plotly.presentation_objs.Presentations)` for help or check out the new [documentation](https://plot.ly/python/presentations-api/)

## [2.1.0] - 2017-10-10
### Updated
- Updated `plotly.min.js` to version 1.31.0.
Expand Down
3 changes: 2 additions & 1 deletion plotly/api/v2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import absolute_import

from plotly.api.v2 import (dash_apps, dashboards, files, folders, grids,
images, plot_schema, plots, users)
images, plot_schema, plots, spectacle_presentations,
users)
32 changes: 32 additions & 0 deletions plotly/api/v2/spectacle_presentations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""
Interface to Plotly's /v2/spectacle-presentations endpoint.
"""
from __future__ import absolute_import

from plotly.api.v2.utils import build_url, request

RESOURCE = 'spectacle-presentations'


def create(body):
"""Create a presentation."""
url = build_url(RESOURCE)
return request('post', url, json=body)


def list():
"""Returns the list of all users' presentations."""
url = build_url(RESOURCE)
return request('get', url)


def retrieve(fid):
"""Retrieve a presentation from Plotly."""
url = build_url(RESOURCE, id=fid)
return request('get', url)


def update(fid, content):
"""Completely update the writable."""
url = build_url(RESOURCE, id=fid)
return request('put', url, json=content)
10 changes: 5 additions & 5 deletions plotly/figure_factory/_scatterplot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import absolute_import

from plotly import exceptions, optional_imports
from plotly import colors, exceptions, optional_imports
from plotly.figure_factory import utils
from plotly.graph_objs import graph_objs
from plotly.tools import make_subplots
Expand Down Expand Up @@ -386,9 +386,9 @@ def scatterplot_theme(dataframe, headers, diag, size, height, width, title,

# Convert colormap to list of n RGB tuples
if colormap_type == 'seq':
foo = utils.color_parser(colormap, utils.unlabel_rgb)
foo = colors.color_parser(colormap, colors.unlabel_rgb)
foo = utils.n_colors(foo[0], foo[1], n_colors_len)
theme = utils.color_parser(foo, utils.label_rgb)
theme = colors.color_parser(foo, colors.label_rgb)

if colormap_type == 'cat':
# leave list of colors the same way
Expand Down Expand Up @@ -556,9 +556,9 @@ def scatterplot_theme(dataframe, headers, diag, size, height, width, title,

# Convert colormap to list of n RGB tuples
if colormap_type == 'seq':
foo = utils.color_parser(colormap, utils.unlabel_rgb)
foo = colors.color_parser(colormap, colors.unlabel_rgb)
foo = utils.n_colors(foo[0], foo[1], len(intervals))
theme = utils.color_parser(foo, utils.label_rgb)
theme = colors.color_parser(foo, colors.label_rgb)

if colormap_type == 'cat':
# leave list of colors the same way
Expand Down
10 changes: 9 additions & 1 deletion plotly/package_data/default-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -35081,6 +35081,7 @@
"role": "info",
"valType": "string"
},
"description": "",
"editType": "calc",
"family": {
"arrayOk": true,
Expand All @@ -35101,6 +35102,7 @@
"size": {
"arrayOk": true,
"editType": "calc",
"min": 1,
"role": "style",
"valType": "number"
},
Expand Down Expand Up @@ -35134,6 +35136,7 @@
"line": {
"color": {
"arrayOk": true,
"dflt": "grey",
"editType": "calc",
"role": "style",
"valType": "color"
Expand All @@ -35148,6 +35151,7 @@
"role": "object",
"width": {
"arrayOk": true,
"dflt": 1,
"editType": "calc",
"role": "style",
"valType": "number"
Expand Down Expand Up @@ -35216,7 +35220,7 @@
},
"columnwidth": {
"arrayOk": true,
"description": "The width of cells.",
"description": "The width of columns expressed as a ratio. Columns fill the available width in proportion of their specified column widths.",
"dflt": null,
"editType": "calc",
"role": "style",
Expand Down Expand Up @@ -35345,6 +35349,7 @@
"role": "info",
"valType": "string"
},
"description": "",
"editType": "calc",
"family": {
"arrayOk": true,
Expand All @@ -35365,6 +35370,7 @@
"size": {
"arrayOk": true,
"editType": "calc",
"min": 1,
"role": "style",
"valType": "number"
},
Expand Down Expand Up @@ -35398,6 +35404,7 @@
"line": {
"color": {
"arrayOk": true,
"dflt": "grey",
"editType": "calc",
"role": "style",
"valType": "color"
Expand All @@ -35412,6 +35419,7 @@
"role": "object",
"width": {
"arrayOk": true,
"dflt": 1,
"editType": "calc",
"role": "style",
"valType": "number"
Expand Down
1 change: 1 addition & 0 deletions plotly/plotly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
get_config,
get_grid,
dashboard_ops,
presentation_ops,
create_animations,
icreate_animations
)
83 changes: 81 additions & 2 deletions plotly/plotly/plotly.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
'sharing': files.FILE_CONTENT[files.CONFIG_FILE]['sharing']
}

SHARING_ERROR_MSG = (
"Whoops, sharing can only be set to either 'public', 'private', or "
"'secret'."
)

# test file permissions and make sure nothing is corrupted
tools.ensure_local_plotly_files()

Expand Down Expand Up @@ -1520,6 +1525,81 @@ def get_dashboard_names(cls):
return [str(dboard['filename']) for dboard in dashboards]


class presentation_ops:
"""
Interface to Plotly's Spectacle-Presentations API.
"""
@classmethod
def upload(cls, presentation, filename, sharing='public', auto_open=True):
"""
Function for uploading presentations to Plotly.

:param (dict) presentation: the JSON presentation to be uploaded. Use
plotly.presentation_objs.Presentation to create presentations
from a Markdown-like string.
:param (str) filename: the name of the presentation to be saved in
your Plotly account. Will overwrite a presentation of the same
name if it already exists in your files.
:param (str) sharing: can be set to either 'public', 'private'
or 'secret'. If 'public', your presentation will be viewable by
all other users. If 'private' only you can see your presentation.
If it is set to 'secret', the url will be returned with a string
of random characters appended to the url which is called a
sharekey. The point of a sharekey is that it makes the url very
hard to guess, but anyone with the url can view the presentation.
:param (bool) auto_open: automatically opens the presentation in the
browser.

See the documentation online for examples.
"""
if sharing == 'public':
world_readable = True
elif sharing in ['private', 'secret']:
world_readable = False
else:
raise exceptions.PlotlyError(
SHARING_ERROR_MSG
)
data = {
'content': json.dumps(presentation),
'filename': filename,
'world_readable': world_readable
}

# lookup if pre-existing filename already exists
try:
lookup_res = v2.files.lookup(filename)
lookup_res.raise_for_status()
matching_file = json.loads(lookup_res.content)

if matching_file['filetype'] != 'spectacle_presentation':
raise exceptions.PlotlyError(
"'{filename}' is already a {filetype} in your account. "
"You can't overwrite a file that is not a spectacle_"
"presentation. Please pick another filename.".format(
filename=filename,
filetype=matching_file['filetype']
)
)
else:
old_fid = matching_file['fid']
res = v2.spectacle_presentations.update(old_fid, data)

except exceptions.PlotlyRequestError:
res = v2.spectacle_presentations.create(data)
res.raise_for_status()

url = res.json()['web_url']

if sharing == 'secret':
url = add_share_key_to_url(url)

if auto_open:
webbrowser.open_new(res.json()['web_url'])

return url


def create_animations(figure, filename=None, sharing='public', auto_open=True):
"""
BETA function that creates plots with animations via `frames`.
Expand Down Expand Up @@ -1712,8 +1792,7 @@ def create_animations(figure, filename=None, sharing='public', auto_open=True):
body['share_key_enabled'] = True
else:
raise exceptions.PlotlyError(
"Whoops, sharing can only be set to either 'public', 'private', "
"or 'secret'."
SHARING_ERROR_MSG
)

response = v2.plots.create(body)
Expand Down
8 changes: 8 additions & 0 deletions plotly/presentation_objs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""
presentation_objs

A wrapper for the spectacle-presentations endpoint.
===========

"""
from . presentation_objs import Presentation
Loading