Skip to content

Commit d6adee0

Browse files
authored
Fix the chrome install issue (#423)
* fix plot.py to work with kaleido v1 * use plotly for chrome depend
1 parent aeb2b1c commit d6adee0

20 files changed

Lines changed: 561 additions & 11 deletions

nanoplotter/plot.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@
55
import sys
66
import logging
77

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+
)
1518

1619
class Plot(object):
1720
"""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):
5659
p = os.path.splitext(self.path)[0] + ".png"
5760
if os.path.exists(p):
5861
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:")
6063
logging.warning(e)
6164

6265
elif self.fig:
@@ -84,13 +87,13 @@ def show(self):
8487

8588
def save_static(self, figformat):
8689
"""
87-
Export a Plotly figure via Kaleido v1’s write_fig_sync.
90+
Export a Plotly figure using Plotly's image writer.
8891
"""
8992
output_path = self.path.replace(".html", f".{figformat}")
9093
try:
91-
write_fig_sync(self.fig, path=output_path)
94+
pio.write_image(self.fig, output_path, format=figformat)
9295
logging.info(f"Saved {output_path} as {figformat}")
9396
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:")
9598
logging.warning(e)
9699

scripts/agm_test.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#! /bin/bash
2+
3+
#SBATCH --time=04-00:00:00
4+
#SBATCH --partition=defq
5+
#SBATCH --mail-user=myemail@email.org
6+
#SBATCH --mail-type=BEGIN,END,FAIL
7+
#SBATCH --ntasks-per-node=64
8+
#SBATCH --mem=128GB
9+
#SBATCH --nodes=1
10+
#SBATCH --job-name=nplot
11+
#SBATCH --comment=nplot
12+
13+
source /path/to/nanoplot_env/bin/activate
14+
15+
# test fresh nanoplot with update
16+
python /path/to/NanoPlot/nanoplot/NanoPlot.py --fastq /path/to/test_file.fastq.gz --verbose --minqual 4 --color red -o scripts/agm_tests

scripts/agm_tests/LengthvsQualityScatterPlot_dot.html

Lines changed: 2 additions & 0 deletions
Large diffs are not rendered by default.
48.7 KB
Loading

scripts/agm_tests/LengthvsQualityScatterPlot_kde.html

Lines changed: 2 additions & 0 deletions
Large diffs are not rendered by default.
86.3 KB
Loading

0 commit comments

Comments
 (0)