Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
47 changes: 25 additions & 22 deletions src/vuegen/quarto_reportview.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys
import textwrap
from pathlib import Path
from typing import List
from typing import List, Optional

import networkx as nx

Expand Down Expand Up @@ -272,10 +272,6 @@ def run_report(self, output_dir: str = BASE_DIR) -> None:
[self.quarto_path, "install", "tinytex", "--no-prompt"],
check=True,
)
subprocess.run(
[self.quarto_path, "install", "chromium", "--no-prompt"],
check=True,
)
try:
subprocess.run(
args,
Expand Down Expand Up @@ -723,13 +719,6 @@ def _generate_dataframe_content(self, dataframe) -> List[str]:
)
# Mapping of file extensions to read functions
read_function_mapping = table_utils.read_function_mapping
# {
# r.DataFrameFormat.CSV.value_with_dot: pd.read_csv,
# r.DataFrameFormat.PARQUET.value_with_dot: pd.read_parquet,
# r.DataFrameFormat.TXT.value_with_dot: pd.read_table,
# r.DataFrameFormat.XLS.value_with_dot: pd.read_excel,
# r.DataFrameFormat.XLSX.value_with_dot: pd.read_excel,
# }
try:
# Check if the file extension matches any DataFrameFormat value
file_extension = Path(dataframe.file_path).suffix.lower()
Expand Down Expand Up @@ -796,8 +785,9 @@ def _generate_dataframe_content(self, dataframe) -> List[str]:
f"sheet_name='{sheet_name}')\n"
)
# Display the dataframe
# ! Probably this still does not work for static reports...
dataframe_content.extend(self._show_dataframe(dataframe))
dataframe_content.extend(
self._show_dataframe(dataframe, suffix=sheet_name)
)

except Exception as e:
self.report.logger.error(
Expand Down Expand Up @@ -880,14 +870,17 @@ def _generate_markdown_content(self, markdown) -> List[str]:
)
return markdown_content

def _show_dataframe(self, dataframe) -> List[str]:
def _show_dataframe(self, dataframe, suffix: Optional[str] = None) -> List[str]:
"""
Appends either a static image or an interactive representation of a DataFrame to the content list.

Parameters
----------
dataframe : DataFrame
The DataFrame object containing the data to display.
The DataFrame object containing the data to display.
suffix : str, optional
A suffix to append to the DataFrame image file name like a sheet name
or another identifier (default is None).

Returns
-------
Expand All @@ -897,9 +890,13 @@ def _show_dataframe(self, dataframe) -> List[str]:
dataframe_content = []
if self.is_report_static:
# Generate path for the DataFrame image
fpath_df_image = (
Path(self.static_dir) / f"{dataframe.title.replace(' ', '_')}.png"
)
fpath_df_image = Path(self.static_dir) / dataframe.title.replace(" ", "_")
if suffix:
fpath_df_image = fpath_df_image.with_stem(
fpath_df_image.stem + f"_{suffix.replace(' ', '_')}"
)
fpath_df_image = fpath_df_image.with_suffix(".png")

dataframe_content.append(
f"df.dfi.export('{Path(fpath_df_image).relative_to('quarto_report').as_posix()}',"
" max_rows=10, max_cols=5, table_conversion='matplotlib')\n```\n"
Expand Down Expand Up @@ -1016,10 +1013,13 @@ def _generate_component_imports(self, component: r.Component) -> List[str]:
"import json",
],
},
"dataframe": [
"static_dataframe": [
"import pandas as pd",
"from itables import show, init_notebook_mode",
"import dataframe_image as dfi",
],
"interactive_dataframe": [
"import pandas as pd",
"from itables import show, init_notebook_mode",
"init_notebook_mode(all_interactive=True)",
],
"markdown": ["import IPython.display as display", "import requests"],
Expand All @@ -1035,7 +1035,10 @@ def _generate_component_imports(self, component: r.Component) -> List[str]:
if plot_type in components_imports["plot"]:
component_imports.extend(components_imports["plot"][plot_type])
elif component_type == r.ComponentType.DATAFRAME:
component_imports.extend(components_imports["dataframe"])
if self.is_report_static:
component_imports.extend(components_imports["static_dataframe"])
else:
component_imports.extend(components_imports["interactive_dataframe"])
elif component_type == r.ComponentType.MARKDOWN:
component_imports.extend(components_imports["markdown"])

Expand Down