@@ -16,28 +16,24 @@ class ReportFormat(StrEnum):
1616class QuartoReportView (r .ReportView ):
1717 """
1818 A ReportView subclass for generating Quarto reports.
19-
20- Methods
21- -------
22- generate_report(output_dir)
23- Generates the qmd file of the quarto report. It creates code for rendering each section and its subsections with all components.
24- run_report(output_dir)
25- Runs the generated quarto report.
2619 """
2720
28- def __init__ (self , identifier : int , name : str , report : r .Report , report_type : r .ReportType ,
21+ BASE_DIR = 'quarto_report'
22+ STATIC_FILES_DIR = os .path .join (BASE_DIR , 'static' )
23+
24+ def __init__ (self , id : int , name : str , report : r .Report , report_type : r .ReportType ,
2925 columns : Optional [List [str ]], report_format : ReportFormat ):
30- super ().__init__ (identifier , name = name , report = report , report_type = report_type , columns = columns )
26+ super ().__init__ (id , name = name , report = report , report_type = report_type , columns = columns )
3127 self .report_format = report_format
3228
33- def generate_report (self , output_dir : str = 'quarto_report/' ) -> None :
29+ def generate_report (self , output_dir : str = BASE_DIR ) -> None :
3430 """
3531 Generates the qmd file of the quarto report. It creates code for rendering each section and its subsections with all components.
3632
3733 Parameters
3834 ----------
3935 output_dir : str, optional
40- The folder where the generated report files will be saved (default is 'quarto_report/' ).
36+ The folder where the generated report files will be saved (default is BASE_DIR ).
4137 """
4238 # Create the output folder if it does not exist
4339 if not os .path .exists (output_dir ):
@@ -93,7 +89,7 @@ def generate_report(self, output_dir: str = 'quarto_report/') -> None:
9389```\n \n """ )
9490 quarto_report .write ("\n " .join (qmd_content ))
9591
96- def run_report (self , output_dir : str = 'quarto_report' ) -> None :
92+ def run_report (self , output_dir : str = BASE_DIR ) -> None :
9793 """
9894 Runs the generated quarto report.
9995
@@ -216,7 +212,7 @@ def _generate_subsection(self, subsection, is_report_static, is_report_revealjs)
216212
217213 return subsection_content , subsection_imports
218214
219- def _generate_plot_content (self , plot , is_report_static ) -> List [str ]:
215+ def _generate_plot_content (self , plot , is_report_static , output_dir : str = STATIC_FILES_DIR ) -> List [str ]:
220216 """
221217 Generate content for a plot component based on the report type.
222218
@@ -231,15 +227,23 @@ def _generate_plot_content(self, plot, is_report_static) -> List[str]:
231227 -------
232228 list : List[str]
233229 The list of content lines for the plot.
230+ output_dir : str, optional
231+ The folder where the static files will be saved (default is STATIC_FILES_DIR).
234232 """
233+ # Create the output folder if it does not exist
234+ if not os .path .exists (output_dir ):
235+ os .mkdir (output_dir )
236+
235237 plot_content = []
236238 plot_content .append (f'### { plot .title } ' )
237239 if plot .plot_type == r .PlotType .INTERACTIVE :
238240 # Define plot path
239241 if is_report_static :
240- static_plot_path = f"quarto_report/{ plot .name .replace (' ' , '_' )} .png"
242+ #static_plot_path = f"{output_dir}/{plot.name.replace(' ', '_')}.png"
243+ static_plot_path = os .path .join (output_dir , f"{ plot .name .replace (' ' , '_' )} .png" )
241244 else :
242- html_plot_file = f"quarto_report/{ plot .name .replace (' ' , '_' )} .html"
245+ #html_plot_file = f"{output_dir}/{plot.name.replace(' ', '_')}.html"
246+ html_plot_file = os .path .join (output_dir , f"{ plot .name .replace (' ' , '_' )} .html" )
243247
244248 if plot .int_visualization_tool == r .IntVisualizationTool .PLOTLY :
245249 plot_content .append (self ._generate_plot_code (plot ))
@@ -402,7 +406,7 @@ def _generate_image_content(self, image_path: str, alt_text: str = "", width: in
402406 return f"""
403407} ){{ width={ width } px height={ height } px fig-align="center"}}\n """
404408
405- def _show_dataframe (self , dataframe , is_report_static ) -> List [str ]:
409+ def _show_dataframe (self , dataframe , is_report_static , output_dir : str = STATIC_FILES_DIR ) -> List [str ]:
406410 """
407411 Appends either a static image or an interactive representation of a DataFrame to the content list.
408412
@@ -417,11 +421,14 @@ def _show_dataframe(self, dataframe, is_report_static) -> List[str]:
417421 -------
418422 list : List[str]
419423 The list of content lines for the DataFrame.
424+ output_dir : str, optional
425+ The folder where the static files will be saved (default is STATIC_FILES_DIR).
420426 """
421427 dataframe_content = []
422428 if is_report_static :
423429 # Generate path for the DataFrame image
424- df_image = f"quarto_report/{ dataframe .name .replace (' ' , '_' )} .png"
430+ #df_image = f"quarto_report/{dataframe.name.replace(' ', '_')}.png"
431+ df_image = os .path .join (output_dir , f"{ dataframe .name .replace (' ' , '_' )} .png" )
425432 dataframe_content .append (f"dfi.export(df, '{ os .path .join ('..' , df_image )} ', max_rows=10, max_cols=5)\n ```\n " )
426433 # Use helper method to add centered image content
427434 dataframe_content .append (self ._generate_image_content (df_image , dataframe .name ))
0 commit comments