Skip to content

Commit fb18a9a

Browse files
committed
Add code to render networks obtained from an html file in quarto reports
1 parent f52608a commit fb18a9a

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

vuegen/quarto_reportview.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -280,18 +280,22 @@ def _generate_plot_content(self, plot, is_report_static, static_dir: str = STATI
280280
else:
281281
plot_content.append(f"""fig_altair\n```\n""")
282282
elif plot.plot_type == r.PlotType.INTERACTIVE_NETWORK:
283-
G = plot.read_network()
284-
num_nodes = G.number_of_nodes()
285-
num_edges = G.number_of_edges()
286-
plot_content.append(f'**Number of nodes:** {num_nodes}\n')
287-
plot_content.append(f'**Number of edges:** {num_edges}\n')
288-
283+
network_data = plot.read_network()
289284
if is_report_static:
290285
plot.save_netwrok_image(G, static_plot_path, "png")
291286
plot_content.append(self._generate_image_content(static_plot_path))
292287
else:
293-
# Get the Network object
294-
net = plot.create_and_save_pyvis_network(G, html_plot_file)
288+
if isinstance(network_data, str) and network_data.endswith('.html'):
289+
# If network_data is the path to an HTML file, just visualize it
290+
html_plot_file = network_data
291+
else:
292+
num_nodes = network_data.number_of_nodes()
293+
num_edges = network_data.number_of_edges()
294+
plot_content.append(f'**Number of nodes:** {num_nodes}\n')
295+
plot_content.append(f'**Number of edges:** {num_edges}\n')
296+
# Get the Network object
297+
net = plot.create_and_save_pyvis_network(network_data, html_plot_file)
298+
295299
plot_content.append(self._generate_plot_code(plot, html_plot_file))
296300
else:
297301
self.report.logger.warning(f"Unsupported plot type: {plot.plot_type}")

vuegen/streamlit_reportview.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,21 +313,17 @@ def _generate_plot_content(self, plot, static_dir: str = STATIC_FILES_DIR) -> Li
313313
plot_content.append(self._generate_plot_code(plot))
314314
elif plot.plot_type == r.PlotType.INTERACTIVE_NETWORK:
315315
network_data = plot.read_network()
316-
317316
if isinstance(network_data, str) and network_data.endswith('.html'):
318-
# If network_data is the path to an HTML file, just visualize the existing HTML file
317+
# If network_data is the path to an HTML file, just visualize it
319318
html_plot_file = network_data
320319
plot_content.append(f"""with open('{html_plot_file}', 'r') as f:
321320
html_data = f.read()""")
322321
else:
323322
# Otherwise, create and save a new pyvis network from the graph
324323
html_plot_file = os.path.join(static_dir, f"{plot.title.replace(' ', '_')}.html")
325324
net = plot.create_and_save_pyvis_network(network_data, html_plot_file)
326-
327-
# Now you can use the existing or newly created HTML file
328325
num_nodes = len(net.nodes)
329326
num_edges = len(net.edges)
330-
331327
plot_content.append(f"""with open('{html_plot_file}', 'r') as f:
332328
html_data = f.read()
333329
st.markdown(f"<p style='text-align: center; color: black;'> <b>Number of nodes:</b> {num_nodes} </p>", unsafe_allow_html=True)

0 commit comments

Comments
 (0)