@@ -586,7 +586,7 @@ def _generate_plot_content(self, plot) -> List[str]:
586586 try :
587587 if plot .plot_type == r .PlotType .STATIC :
588588 plot_content .append (
589- f"\n st.image('{ plot .file_path } ', caption='{ plot .caption } ', use_column_width=True)\n "
589+ f"\n st.image('{ Path ( plot .file_path ). relative_to ( Path . cwd ()). as_posix () } ', caption='{ plot .caption } ', use_column_width=True)\n "
590590 )
591591 elif plot .plot_type == r .PlotType .PLOTLY :
592592 plot_content .append (self ._generate_plot_code (plot ))
@@ -601,7 +601,7 @@ def _generate_plot_content(self, plot) -> List[str]:
601601 # Otherwise, create and save a new pyvis network from the netowrkx graph
602602 html_plot_file = (
603603 Path (self .static_dir ) / f"{ plot .title .replace (' ' , '_' )} .html"
604- )
604+ ). resolve ()
605605 _ = plot .create_and_save_pyvis_network (
606606 networkx_graph , html_plot_file
607607 )
@@ -616,13 +616,13 @@ def _generate_plot_content(self, plot) -> List[str]:
616616 f"""
617617response = requests.get('{ html_plot_file } ')
618618response.raise_for_status()
619- html_data = response.text\n """
619+ html_content = response.text\n """
620620 )
621621 else :
622622 plot_content .append (
623623 f"""
624- with open('{ html_plot_file } ', 'r') as f :
625- html_data = f .read()\n """
624+ with open('{ Path ( html_plot_file ). relative_to ( Path . cwd ()) } ', 'r') as html_file :
625+ html_content = html_file .read()\n """
626626 )
627627
628628 # Append the code for additional information (nodes and edges count)
@@ -670,7 +670,7 @@ def _generate_plot_code(self, plot) -> str:
670670plot_json = json.loads(response.text)\n """
671671 else : # If it's a local file
672672 plot_code = f"""
673- with open('{ Path (plot .file_path ).as_posix ()} ', 'r') as plot_file:
673+ with open('{ Path (plot .file_path ).relative_to ( Path . cwd ()). as_posix ()} ', 'r') as plot_file:
674674 plot_json = json.load(plot_file)\n """
675675
676676 # Add specific code for each visualization tool
@@ -693,7 +693,7 @@ def _generate_plot_code(self, plot) -> str:
693693control_layout = st.checkbox('Add panel to control layout', value=True)
694694net_html_height = 1200 if control_layout else 630
695695# Load HTML into HTML component for display on Streamlit
696- st.components.v1.html(html_data , height=net_html_height)\n """
696+ st.components.v1.html(html_content , height=net_html_height)\n """
697697 return plot_code
698698
699699 def _generate_dataframe_content (self , dataframe ) -> List [str ]:
@@ -740,7 +740,7 @@ def _generate_dataframe_content(self, dataframe) -> List[str]:
740740 # Load the DataFrame using the correct function
741741 read_function = read_function_mapping [file_extension ]
742742 dataframe_content .append (
743- f"""df = pd.{ read_function .__name__ } ('{ dataframe .file_path } ')\n """
743+ f"""df = pd.{ read_function .__name__ } ('{ Path ( dataframe .file_path ). relative_to ( Path . cwd ()). as_posix () } ')\n """
744744 )
745745
746746 # Displays a DataFrame using AgGrid with configurable options.
@@ -819,7 +819,7 @@ def _generate_markdown_content(self, markdown) -> List[str]:
819819 else : # If it's a local file
820820 markdown_content .append (
821821 f"""
822- with open('{ ( Path (".." ) / markdown .file_path ).as_posix ()} ', 'r') as markdown_file:
822+ with open('{ Path (markdown .file_path ). relative_to ( Path . cwd () ).as_posix ()} ', 'r') as markdown_file:
823823 markdown_content = markdown_file.read()\n """
824824 )
825825 # Code to display md content
@@ -879,7 +879,7 @@ def _generate_html_content(self, html) -> List[str]:
879879 # If it's a local file
880880 html_content .append (
881881 f"""
882- with open('{ ( Path (".." ) / html .file_path ).as_posix ()} ', 'r', encoding='utf-8') as html_file:
882+ with open('{ Path (html .file_path ). relative_to ( Path . cwd () ).as_posix ()} ', 'r', encoding='utf-8') as html_file:
883883 html_content = html_file.read()\n """
884884 )
885885
0 commit comments