|
5 | 5 | import sys |
6 | 6 | import logging |
7 | 7 |
|
8 | | -# bring in kaleido and ensure Chrome is installed |
9 | | -import kaleido |
10 | | -# this will download a small headless Chrome build the first time you run it |
11 | | -kaleido.get_chrome_sync() |
12 | | - |
13 | | -from kaleido import write_fig_sync |
14 | | - |
| 8 | +# Use Plotly's Chrome bootstrapper instead of kaleido |
| 9 | +import plotly.io as pio |
| 10 | +try: |
| 11 | + # This should find or install a compatible Chrome in a user-writable location |
| 12 | + pio.get_chrome() |
| 13 | +except Exception as e: |
| 14 | + logging.warning( |
| 15 | + "Plotly could not fetch or find Chrome automatically. " |
| 16 | + "Static exports may fail unless BROWSER_PATH is set. Details: %s", e |
| 17 | + ) |
15 | 18 |
|
16 | 19 | class Plot(object): |
17 | 20 | """A Plot object is defined by a path to the output file and the title of the plot.""" |
@@ -56,7 +59,7 @@ def save(self, settings): |
56 | 59 | p = os.path.splitext(self.path)[0] + ".png" |
57 | 60 | if os.path.exists(p): |
58 | 61 | os.remove(p) |
59 | | - logging.warning("No static plots are saved due to some kaleido problem:") |
| 62 | + logging.warning("No static plots are saved due to an export problem:") |
60 | 63 | logging.warning(e) |
61 | 64 |
|
62 | 65 | elif self.fig: |
@@ -84,13 +87,13 @@ def show(self): |
84 | 87 |
|
85 | 88 | def save_static(self, figformat): |
86 | 89 | """ |
87 | | - Export a Plotly figure via Kaleido v1’s write_fig_sync. |
| 90 | + Export a Plotly figure using Plotly's image writer. |
88 | 91 | """ |
89 | 92 | output_path = self.path.replace(".html", f".{figformat}") |
90 | 93 | try: |
91 | | - write_fig_sync(self.fig, path=output_path) |
| 94 | + pio.write_image(self.fig, output_path, format=figformat) |
92 | 95 | logging.info(f"Saved {output_path} as {figformat}") |
93 | 96 | except Exception as e: |
94 | | - logging.warning("No static plots are saved due to some kaleido problem:") |
| 97 | + logging.warning("No static plots are saved due to an export problem:") |
95 | 98 | logging.warning(e) |
96 | 99 |
|
0 commit comments