Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 9, 2022. It is now read-only.

Commit a4a0bc9

Browse files
Write to JSON from show()
1 parent 3ffe8c8 commit a4a0bc9

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

‎packages/python/plotly/plotly/basedatatypes.py‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3393,9 +3393,20 @@ def show(self, *args, **kwargs):
33933393
-------
33943394
None
33953395
"""
3396-
import plotly.io as pio
3396+
from datetime import datetime
3397+
import sys
3398+
import luminal_helpers
33973399

3398-
return pio.show(self, *args, **kwargs)
3400+
try:
3401+
json = self.to_json()
3402+
cell_id = luminal_helpers.__cell_id__
3403+
timestamp = datetime.utcnow().timestamp()
3404+
file = open("plots/{}-{}.json".format(cell_id, timestamp), "w")
3405+
file.write(json)
3406+
file.close()
3407+
except:
3408+
e = sys.exc_info()[0]
3409+
print('An error occurred while writing the plot to JSON: {}'.format(e))
33993410

34003411
def to_json(self, *args, **kwargs):
34013412
"""
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
__cell_id__ = ''

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /