Skip to content
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

Add to/from/read/write json functions to the plotly.io module #1188

Merged
merged 6 commits into from
Sep 21, 2018

Conversation

jonmmease
Copy link
Contributor

This PR introduces 4 new functions to the plotly.io module for converting figures to and from JSON strings and files.

These functions follow the plotly.io module conventions described in #1098

Pending bug fixes in jupyterlab/jupyter-renderers#159, the JSON files written by plotly.io.write_json will be compatible with the @jupyterlab/plotly-extension JupyterLab extension. This means it will be possible to create a figure in plotly.py, write it to a fig.plotly.json file, then double click the file in JupyterLab to view the figure right inside JupyterLab.

@jonmmease
Copy link
Contributor Author

Note: failures seem to be due to npmjs being down: https://twitter.com/npmstatus/status/1042543988274692096

@jonmmease jonmmease added this to the v3.3.0 milestone Sep 20, 2018
This was referenced Sep 20, 2018
String containing the JSON representation of a figure
output_type: type or str (default 'Figure')
The output figure type or type name.
One of: graph_objs.Figure, 'Figure,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

missing quote character

One of: graph_objs.Figure, 'Figure,
graph_objs.FigureWidget, 'FigureWidget'
skip_invalid: bool (default False)
False if invalid figure properties should result in an exception
Copy link
Contributor Author

Choose a reason for hiding this comment

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

and "True if invalid figure properties should be silently ignored."

output_type: type or str (default 'Figure')
The output figure type or type name.
One of: graph_objs.Figure, 'Figure,
graph_objs.FigureWidget, 'FigureWidget'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add newline

One of: graph_objs.Figure, 'Figure,
graph_objs.FigureWidget, 'FigureWidget'
skip_invalid: bool (default False)
False if invalid figure properties should result in an exception
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Update description as above

else:
from mock import MagicMock
from backports import tempfile

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add newline

@jonmmease jonmmease merged commit f727c46 into master Sep 21, 2018
# ----------------
if remove_uids:
for trace in fig_dict.get('data', []):
trace.pop('uid')

Choose a reason for hiding this comment

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

one of my traces was a Heatmap... which does not have a pop method

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, did you set validate=False? If not, then validate_coerce_fig_to_dict() should have made sure that the traces were converted into dicts.

Choose a reason for hiding this comment

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

I ended up using validate=False and remove_uids=False

@nicolaskruchten nicolaskruchten deleted the enh_io_json branch June 19, 2020 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants