Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,11 +2,8 @@ import streamlit as st
|
|
2 |
import matplotlib.pyplot as plt
|
3 |
import networkx as nx
|
4 |
|
5 |
-
# Add a
|
6 |
-
st.
|
7 |
-
|
8 |
-
# Add a radio button for selecting the graph type
|
9 |
-
option = st.radio("Choose a graph type:", ("Default Example", "Create your own"))
|
10 |
|
11 |
# Function to display properties and graph
|
12 |
def display_graph_properties(G):
|
@@ -53,17 +50,22 @@ def display_graph_properties(G):
|
|
53 |
nx.draw(G, pos=pos, with_labels=True, node_color='lightblue', node_size=500, font_size=10, font_weight='bold')
|
54 |
st.pyplot(plt)
|
55 |
|
56 |
-
#
|
57 |
-
if
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
# Create your own graph
|
62 |
-
elif option == "Create your own":
|
63 |
-
# Let the user input number of nodes and edges
|
64 |
-
num_nodes = st.number_input("Number of nodes:", min_value=2, max_value=50, value=5)
|
65 |
-
num_edges = st.number_input("Number of edges per group (for lollipop graph):", min_value=1, max_value=10, value=3)
|
66 |
|
67 |
-
|
68 |
-
|
|
|
69 |
display_graph_properties(G)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
import matplotlib.pyplot as plt
|
3 |
import networkx as nx
|
4 |
|
5 |
+
# Add a sidebar with options
|
6 |
+
sidebar_option = st.sidebar.radio("Select an option", ["Select an option", "Basic: Properties"])
|
|
|
|
|
|
|
7 |
|
8 |
# Function to display properties and graph
|
9 |
def display_graph_properties(G):
|
|
|
50 |
nx.draw(G, pos=pos, with_labels=True, node_color='lightblue', node_size=500, font_size=10, font_weight='bold')
|
51 |
st.pyplot(plt)
|
52 |
|
53 |
+
# Only display Basic: Properties when it is selected from the sidebar
|
54 |
+
if sidebar_option == "Basic: Properties":
|
55 |
+
# Add a radio button for selecting the graph type
|
56 |
+
option = st.radio("Choose a graph type:", ("Default Example", "Create your own"))
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
+
# Default example
|
59 |
+
if option == "Default Example":
|
60 |
+
G = nx.lollipop_graph(4, 6)
|
61 |
display_graph_properties(G)
|
62 |
+
|
63 |
+
# Create your own graph
|
64 |
+
elif option == "Create your own":
|
65 |
+
# Let the user input number of nodes and edges
|
66 |
+
num_nodes = st.number_input("Number of nodes:", min_value=2, max_value=50, value=5)
|
67 |
+
num_edges = st.number_input("Number of edges per group (for lollipop graph):", min_value=1, max_value=10, value=3)
|
68 |
+
|
69 |
+
if num_nodes >= 2 and num_edges >= 1:
|
70 |
+
G = nx.lollipop_graph(num_nodes, num_edges)
|
71 |
+
display_graph_properties(G)
|