Skip to content

Commit 99985d5

Browse files
enryHenryhsayalaruano
authored
🐛 Save streamlit rand quarto reports with Posix and change str paths to Path (#78)
* 🐛 copyright symbol not recognized on Windows - use ASCI complient spelling - maybe unicode symbols could be used? * 🐛 save streamlit report files with Posix path for each component, section etc * 🐛 Fix(quarto_reportview.py): Replace copyright symbol in quarto reports for Windows compatibility * 🎨 Style(streamlit_reportview.py): use Papth lib for all paths in the streamlit reports * 🎨 Style(quarto_reportview.py): use Path lib for all paths in the quarto reports * 🐛 Fix: correct terminal message after execution * 🎨 Style: add black format * 📝 Docs: remove yaml file example from the EMP folder --------- Co-authored-by: enryh <[email protected]> Co-authored-by: Sebastián Ayala Ruano <[email protected]> Co-authored-by: sayalaruano <[email protected]>
1 parent 33ffc65 commit 99985d5

File tree

6 files changed

+58
-222
lines changed

6 files changed

+58
-222
lines changed

docs/example_data/Earth_microbiome_vuegen_demo_notebook/Earth_microbiome_vuegen_demo_notebook_config.yaml

Lines changed: 0 additions & 140 deletions
This file was deleted.

src/vuegen/config_manager.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ def _create_component_config_fromfile(self, file_path: Path) -> Dict[str, str]:
6363

6464
# Add title, file path, and description
6565
component_config["title"] = self._create_title_fromdir(file_path.name)
66-
component_config["file_path"] = str(file_path.resolve())
66+
component_config["file_path"] = (
67+
file_path.resolve().as_posix()
68+
) # ! needs to be posix for all OS support
6769
component_config["description"] = ""
6870
component_config["caption"] = ""
6971

src/vuegen/quarto_reportview.py

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class QuartoReportView(r.ReportView):
1616
"""
1717

1818
BASE_DIR = "quarto_report"
19-
STATIC_FILES_DIR = os.path.join(BASE_DIR, "static")
19+
STATIC_FILES_DIR = Path(BASE_DIR) / "static"
2020

2121
def __init__(self, report: r.Report, report_type: r.ReportType):
2222
super().__init__(report=report, report_type=report_type)
@@ -124,9 +124,7 @@ def generate_report(
124124
report_formatted_imports = "\n".join(report_unique_imports)
125125

126126
# Write the navigation and general content to a Python file
127-
with open(
128-
os.path.join(output_dir, f"{self.BASE_DIR}.qmd"), "w"
129-
) as quarto_report:
127+
with open(Path(output_dir) / f"{self.BASE_DIR}.qmd", "w") as quarto_report:
130128
quarto_report.write(yaml_header)
131129
quarto_report.write(
132130
f"""\n```{{python}}
@@ -156,15 +154,15 @@ def run_report(self, output_dir: str = BASE_DIR) -> None:
156154
"""
157155
try:
158156
subprocess.run(
159-
["quarto", "render", os.path.join(output_dir, f"{self.BASE_DIR}.qmd")],
157+
["quarto", "render", Path(output_dir) / f"{self.BASE_DIR}.qmd"],
160158
check=True,
161159
)
162160
if self.report_type == r.ReportType.JUPYTER:
163161
subprocess.run(
164162
[
165163
"quarto",
166164
"convert",
167-
os.path.join(output_dir, f"{self.BASE_DIR}.qmd"),
165+
Path(output_dir) / f"{self.BASE_DIR}.qmd",
168166
],
169167
check=True,
170168
)
@@ -227,7 +225,7 @@ def _create_yaml_header(self) -> str:
227225
<a href="https://github.com/Multiomics-Analytics-Group/vuegen" target="_blank">
228226
<img src="https://raw.githubusercontent.com/Multiomics-Analytics-Group/vuegen/main/docs/images/vuegen_logo.svg" alt="VueGen" width="65px">
229227
</a>
230-
| © 2025 <a href="https://github.com/Multiomics-Analytics-Group" target="_blank">Multiomics Network Analytics Group (MoNA)</a>
228+
| Copyright 2025 <a href="https://github.com/Multiomics-Analytics-Group" target="_blank">Multiomics Network Analytics Group (MoNA)</a>
231229
</footer>""",
232230
r.ReportType.PDF: """
233231
pdf:
@@ -273,7 +271,7 @@ def _create_yaml_header(self) -> str:
273271
<a href="https://github.com/Multiomics-Analytics-Group/vuegen" target="_blank">
274272
<img src="https://raw.githubusercontent.com/Multiomics-Analytics-Group/vuegen/main/docs/images/vuegen_logo.svg" alt="VueGen" width="65px">
275273
</a>
276-
| © 2025 <a href="https://github.com/Multiomics-Analytics-Group" target="_blank">Multiomics Network Analytics Group (MoNA)</a>
274+
| Copyright 2025 <a href="https://github.com/Multiomics-Analytics-Group" target="_blank">Multiomics Network Analytics Group (MoNA)</a>
277275
</footer>""",
278276
r.ReportType.PPTX: """
279277
pptx:
@@ -304,7 +302,7 @@ def _create_yaml_header(self) -> str:
304302
<a href="https://github.com/Multiomics-Analytics-Group/vuegen" target="_blank">
305303
<img src="../docs/images/vuegen_logo.svg" alt="VueGen" width="65px">
306304
</a>
307-
| © 2025 <a href="https://github.com/Multiomics-Analytics-Group" target="_blank">Multiomics Network Analytics Group (MoNA)</a>
305+
| Copyright 2025 <a href="https://github.com/Multiomics-Analytics-Group" target="_blank">Multiomics Network Analytics Group (MoNA)</a>
308306
</footer>""",
309307
}
310308
# Create a key based on the report type and format
@@ -413,13 +411,9 @@ def _generate_plot_content(
413411

414412
# Define plot path
415413
if is_report_static:
416-
static_plot_path = os.path.join(
417-
static_dir, f"{plot.title.replace(' ', '_')}.png"
418-
)
414+
static_plot_path = Path(static_dir) / f"{plot.title.replace(' ', '_')}.png"
419415
else:
420-
html_plot_file = os.path.join(
421-
static_dir, f"{plot.title.replace(' ', '_')}.html"
422-
)
416+
html_plot_file = Path(static_dir) / f"{plot.title.replace(' ', '_')}.html"
423417

424418
# Add content for the different plot types
425419
try:
@@ -431,7 +425,7 @@ def _generate_plot_content(
431425
plot_content.append(self._generate_plot_code(plot))
432426
if is_report_static:
433427
plot_content.append(
434-
f"""fig_plotly.write_image("{os.path.abspath(static_plot_path)}")\n```\n"""
428+
f"""fig_plotly.write_image("{static_plot_path.resolve()}")\n```\n"""
435429
)
436430
plot_content.append(self._generate_image_content(static_plot_path))
437431
else:
@@ -440,7 +434,7 @@ def _generate_plot_content(
440434
plot_content.append(self._generate_plot_code(plot))
441435
if is_report_static:
442436
plot_content.append(
443-
f"""fig_altair.save("{os.path.abspath(static_plot_path)}")\n```\n"""
437+
f"""fig_altair.save("{static_plot_path.resolve()}")\n```\n"""
444438
)
445439
plot_content.append(self._generate_image_content(static_plot_path))
446440
else:
@@ -513,7 +507,7 @@ def _generate_plot_code(self, plot, output_file="") -> str:
513507
plot_json = response.text\n"""
514508
else: # If it's a local file
515509
plot_code += f"""
516-
with open('{os.path.join("..", plot.file_path)}', 'r') as plot_file:
510+
with open('{Path("..") / plot.file_path}', 'r') as plot_file:
517511
plot_json = plot_file.read()\n"""
518512
# Add specific code for each visualization tool
519513
if plot.plot_type == r.PlotType.PLOTLY:
@@ -527,7 +521,7 @@ def _generate_plot_code(self, plot, output_file="") -> str:
527521
if is_url(plot.file_path) and plot.file_path.endswith(".html"):
528522
iframe_src = output_file
529523
else:
530-
iframe_src = os.path.join("..", output_file)
524+
iframe_src = Path("..") / output_file
531525

532526
# Embed the HTML file in an iframe
533527
plot_code = f"""
@@ -573,7 +567,7 @@ def _generate_dataframe_content(self, dataframe, is_report_static) -> List[str]:
573567
}
574568
try:
575569
# Check if the file extension matches any DataFrameFormat value
576-
file_extension = os.path.splitext(dataframe.file_path)[1].lower()
570+
file_extension = Path(dataframe.file_path).suffix.lower()
577571
if not any(
578572
file_extension == fmt.value_with_dot for fmt in r.DataFrameFormat
579573
):
@@ -585,7 +579,7 @@ def _generate_dataframe_content(self, dataframe, is_report_static) -> List[str]:
585579
file_path = (
586580
dataframe.file_path
587581
if is_url(dataframe.file_path)
588-
else os.path.join("..", dataframe.file_path)
582+
else Path("..") / dataframe.file_path
589583
)
590584

591585
# Load the DataFrame using the correct function
@@ -648,7 +642,7 @@ def _generate_markdown_content(self, markdown) -> List[str]:
648642
else: # If it's a local file
649643
markdown_content.append(
650644
f"""
651-
with open('{os.path.join("..", markdown.file_path)}', 'r') as markdown_file:
645+
with open('{Path("..") / markdown.file_path}', 'r') as markdown_file:
652646
markdown_content = markdown_file.read()\n"""
653647
)
654648

@@ -694,7 +688,7 @@ def _generate_html_content(self, html) -> List[str]:
694688
iframe_src = (
695689
html.file_path
696690
if is_url(html.file_path)
697-
else os.path.join("..", html.file_path)
691+
else Path("..") / html.file_path
698692
)
699693
iframe_code = f"""
700694
<div style="text-align: center;">
@@ -769,11 +763,9 @@ def _show_dataframe(
769763
dataframe_content = []
770764
if is_report_static:
771765
# Generate path for the DataFrame image
772-
df_image = os.path.join(
773-
static_dir, f"{dataframe.title.replace(' ', '_')}.png"
774-
)
766+
df_image = Path(static_dir) / f"{dataframe.title.replace(' ', '_')}.png"
775767
dataframe_content.append(
776-
f"df.dfi.export('{os.path.abspath(df_image)}', max_rows=10, max_cols=5)\n```\n"
768+
f"df.dfi.export('{Path(df_image).resolve()}', max_rows=10, max_cols=5)\n```\n"
777769
)
778770
# Use helper method to add centered image content
779771
dataframe_content.append(self._generate_image_content(df_image))

src/vuegen/report.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ def create_and_save_pyvis_network(self, G: nx.Graph, output_file: str) -> Networ
382382
net.show_buttons(filter_=["physics"])
383383

384384
# Save the network as an HTML file
385-
net.save_graph(output_file)
385+
net.save_graph(str(output_file))
386386
self.logger.info(f"PyVis network created and saved as: {output_file}.")
387387
return net
388388

0 commit comments

Comments
 (0)