File size: 509 Bytes
f96c606
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import streamlit as st
from pyvis.network import Network
import networkx as nx
import tempfile

# Create a graph
G = nx.fast_gnp_random_graph(n=10, p=0.2)

# Convert NetworkX graph to PyVis graph
nt = Network("500px", "500px", notebook=True)
nt.from_nx(G)

# Generate the graph to an HTML file
tmp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.html')
nt.save_graph(tmp_file.name)

# Use Streamlit components to display the graph
st.components.v1.html(tmp_file.read(), height=500, scrolling=False)