import streamlit as st
import streamlit.components.v1 as components
import networkx as nx
import json
from pyvis.network import Network
st.set_page_config(layout="wide")
st.title("đ Education Network Explorer")
# Add introduction and instructions
st.markdown("""
Welcome to the **Education Network Explorer** â an interactive dashboard designed to help you explore relationships between key education-related topics on Twitter.
â Nodes represent topics like *school choice* or *teacher unions*.
â Edges connect topics that share common influencers.
â Hover over a node to view:
â The number of unique influencers discussing that topic
â The top 3â5 most active influencers
Use this dashboard to identify clusters, central topics, and influencer patterns across the education discourse.
""")
st.markdown("---") # Visual separator
# Section: Interactive Graph
st.subheader("đ Interactive Network Graph")
with open("education_graph_preview.html", "r", encoding="utf-8") as f:
graph_html = f.read()
components.html(graph_html, height=750, scrolling=True)
st.markdown("---")
# Section: Topic Selector for Subgraph
st.subheader("đ¯ Explore by Topic")
selected_topic = st.selectbox("Select a topic to view its connections", sorted([n for n in nx_graph.nodes]))
# Build subgraph of selected topic and its neighbors
sub_nodes = [selected_topic] + list(nx_graph.neighbors(selected_topic))
subgraph = nx_graph.subgraph(sub_nodes)
# Generate pyvis visualization for subgraph
net = Network(height="750px", width="100%", notebook=False, bgcolor="#ffffff", font_color="black")
net.barnes_hut()
net.from_nx(subgraph)
# Customize node hover data
for node in net.nodes:
topic = node['id']
topic_data = nx_graph.nodes[topic]
label = topic_data.get("label", topic)
count = topic_data.get("influencer_count", 0)
top_users = topic_data.get("top_influencers", [])
node['title'] = f"{label}
Influencers: {count}
Top: {', '.join(top_users)}"
node['label'] = label
# Save subgraph
net.save_graph("education_graph_filtered.html")
with open("education_graph_filtered.html", "r", encoding="utf-8") as f:
filtered_html = f.read()
components.html(filtered_html, height=750, scrolling=True)
st.markdown("---")
# Optional: Placeholder for metadata/filters
st.markdown("âšī¸ *Click on a node in the graph to view influencer data in the tooltip.*")