Skip to content

Commit c67c27b

Browse files
committed
Move code to create static folder from the genrate_content_plot to the generate_report method in the StreamlitReportView class
1 parent 4f8426f commit c67c27b

File tree

3 files changed

+19
-23
lines changed

3 files changed

+19
-23
lines changed

report/quarto_reportview.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ def generate_report(self, output_dir: str = BASE_DIR, static_dir: str = STATIC_F
106106
```\n\n""")
107107
quarto_report.write("\n".join(qmd_content))
108108
self.report.logger.info(f"Created qmd script to render the app: {self.BASE_DIR}.qmd")
109+
109110
except Exception as e:
110111
self.report.logger.error(f"An error occurred while generating the report: {str(e)}")
111112
raise

report/streamlit_reportview.py

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,30 @@ class StreamlitReportView(r.WebAppReportView):
1717
def __init__(self, id: int, name: str, report: r.Report, report_type: r.ReportType, columns: Optional[List[str]]):
1818
super().__init__(id, name=name, report=report, report_type = report_type, columns=columns)
1919

20-
def generate_report(self, output_dir: str = SECTIONS_DIR) -> None:
20+
def generate_report(self, output_dir: str = SECTIONS_DIR, static_dir: str = STATIC_FILES_DIR) -> None:
2121
"""
2222
Generates the Streamlit report and creates Python files for each section and its subsections and plots.
2323
2424
Parameters
2525
----------
2626
output_dir : str, optional
2727
The folder where the generated report files will be saved (default is SECTIONS_DIR).
28+
static_dir : str, optional
29+
The folder where the static files will be saved (default is STATIC_FILES_DIR).
2830
"""
2931
self.report.logger.debug(f"Generating '{self.report_type}' report in directory: '{output_dir}'")
3032

31-
# Create the output folder if it does not exist
32-
#if not os.path.exists(output_dir):
33-
# os.makedirs(output_dir, exist_ok=True)
33+
# Create the output folder
3434
if create_folder(output_dir, is_nested=True):
35-
self.report.logger.debug(f"Created output directory: '{output_dir}'")
35+
self.report.logger.info(f"Created output directory: '{output_dir}'")
36+
else:
37+
self.report.logger.info(f"Output directory already existed: '{output_dir}'")
38+
39+
# Create the static folder
40+
if create_folder(static_dir):
41+
self.report.logger.info(f"Created output directory for static content: '{static_dir}'")
3642
else:
37-
self.report.logger.debug(f"Output directory already existed: '{output_dir}'")
43+
self.report.logger.info(f"Output directory for static content already existed: '{static_dir}'")
3844

3945
try:
4046
self.report.logger.debug("Processing app navigation code.")
@@ -56,8 +62,7 @@ def generate_report(self, output_dir: str = SECTIONS_DIR) -> None:
5662
subsection_page_vars = []
5763
section_name_var = section.name.replace(" ", "_")
5864
section_dir_path = os.path.join(output_dir, section_name_var)
59-
#if not os.path.exists(os.path.join(output_dir, section_name_var)):
60-
# os.mkdir(os.path.join(output_dir, section_name_var))
65+
6166
if create_folder(section_dir_path):
6267
self.report.logger.debug(f"Created section directory: {section_dir_path}")
6368
else:
@@ -150,8 +155,6 @@ def _generate_home_section(self, output_dir: str, report_manag_content: list) ->
150155
try:
151156
# Create folder for the home page
152157
home_dir_path = os.path.join(output_dir, "Home")
153-
#if not os.path.exists(home_dir_path):
154-
#os.mkdir(home_dir_path)
155158
if create_folder(home_dir_path):
156159
self.report.logger.debug(f"Created home directory: {home_dir_path}")
157160
else:
@@ -271,7 +274,7 @@ def _generate_subsection(self, subsection) -> tuple[List[str], List[str]]:
271274
self.report.logger.info(f"Generated content and imports for subsection: '{subsection.name}'")
272275
return subsection_content, subsection_imports
273276

274-
def _generate_plot_content(self, plot, output_dir: str = STATIC_FILES_DIR) -> List[str]:
277+
def _generate_plot_content(self, plot, static_dir: str = STATIC_FILES_DIR) -> List[str]:
275278
"""
276279
Generate content for a plot component based on the plot type (static or interactive).
277280
@@ -284,17 +287,9 @@ def _generate_plot_content(self, plot, output_dir: str = STATIC_FILES_DIR) -> Li
284287
-------
285288
list : List[str]
286289
The list of content lines for the plot.
287-
output_dir : str, optional
290+
static_dir : str, optional
288291
The folder where the static files will be saved (default is STATIC_FILES_DIR).
289292
"""
290-
# Create the output folder if it does not exist
291-
#if not os.path.exists(output_dir):
292-
# os.mkdir(output_dir)
293-
if create_folder(output_dir):
294-
self.report.logger.debug(f"Created output directory for static content: {output_dir}")
295-
else:
296-
self.report.logger.debug(f"Output directory for static content already existed: {output_dir}")
297-
298293
plot_content = []
299294
plot_content.append(self._format_text(text=plot.title, type='header', level=4, color='#2b8cbe'))
300295

@@ -308,7 +303,7 @@ def _generate_plot_content(self, plot, output_dir: str = STATIC_FILES_DIR) -> Li
308303
elif plot.int_visualization_tool == r.IntVisualizationTool.PYVIS:
309304
# For PyVis, handle the network visualization
310305
G = plot.read_network()
311-
html_plot_file = os.path.join(output_dir, f"{plot.name.replace(' ', '_')}.html")
306+
html_plot_file = os.path.join(static_dir, f"{plot.name.replace(' ', '_')}.html")
312307
net = plot.create_and_save_pyvis_network(G, html_plot_file)
313308
num_nodes = len(net.nodes)
314309
num_edges = len(net.edges)

report_metadata_micw2graph.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ report:
1313
and potential ecological functions.
1414
graphical_abstract: "example_data/MicW2Graph/Methods_MicW2Graph.png"
1515
logo: "example_data/mona_logo.png"
16-
report_type: "document"
17-
report_format: "html"
16+
report_type: "streamlit"
17+
report_format: ""
1818
sections:
1919
- id: 21324
2020
name: "Exploratory Data analysis"

0 commit comments

Comments
 (0)