Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,12 +16,13 @@ st.title("Faculty Collaboration Network Analysis -FY23 & FY24")
|
|
| 16 |
# Load data
|
| 17 |
@st.cache_data
|
| 18 |
def load_data():
|
| 19 |
-
award_df = pd.read_csv('
|
| 20 |
-
|
| 21 |
-
|
|
|
|
| 22 |
|
| 23 |
|
| 24 |
-
award_df, faculty_college_df = load_data()
|
| 25 |
award_df.columns = award_df.columns.str.strip() # Clean column names
|
| 26 |
faculty_college_df = faculty_college_df.apply(lambda x: x.str.strip() if x.dtype == "object" else x)
|
| 27 |
|
|
@@ -41,12 +42,31 @@ def create_network(df, college_map):
|
|
| 41 |
# faculty_colleges = defaultdict(list)
|
| 42 |
faculty_amounts = defaultdict(float)
|
| 43 |
|
| 44 |
-
colorblind_palette =[
|
| 45 |
-
'#FF6B6B', '#4ECDC4', '#45B7D1', '#96CEB4',
|
| 46 |
-
'#FFEEAD', '#D4A5A5', '#779ECB', '#FFB347',
|
| 47 |
-
'#B1DDF3', '#A8E6CF', '#DCEDC1', '#FFD3B6',
|
| 48 |
-
'#FFAAA5', '#C8C6A7', '#92967D'
|
| 49 |
-
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
for _, row in df.iterrows():
|
| 52 |
# Process PI information
|
|
@@ -102,7 +122,7 @@ def create_network(df, college_map):
|
|
| 102 |
college_colors[college] = colorblind_palette[i % len(colorblind_palette)]
|
| 103 |
|
| 104 |
# Add explicit color for Unknown
|
| 105 |
-
college_colors['Unknown'] = '#888888'
|
| 106 |
# unique_colleges = sorted(list(set(college_map.values())))
|
| 107 |
# colormap = plt.cm.get_cmap('tab20', len(unique_colleges))
|
| 108 |
# college_colors = {college: to_hex(colormap(i)) for i, college in enumerate(unique_colleges)}
|
|
@@ -127,8 +147,7 @@ def create_network(df, college_map):
|
|
| 127 |
college = college_assignment.get(node, 'Unknown')
|
| 128 |
G.nodes[node]['color'] = college_colors.get(college_map.get(node, 'Unknown'), '#888888')
|
| 129 |
G.nodes[node]['size'] = node_sizes[i]
|
| 130 |
-
G.nodes[node]['title'] = (f"{node} | College: {college_map.get(node, 'Unknown')}"
|
| 131 |
-
f" | Total Funding: ${faculty_amounts.get(node, 0):,.2f}")
|
| 132 |
|
| 133 |
return G, college_colors
|
| 134 |
|
|
@@ -156,7 +175,7 @@ with open('network.html', 'r', encoding='utf-8') as f:
|
|
| 156 |
st.markdown("""
|
| 157 |
**Network Interaction Guide:**
|
| 158 |
- Drag nodes to rearrange the network
|
| 159 |
-
- Scroll to zoom in/out to see the details: Faculty Name | College
|
| 160 |
- Click and drag background to pan
|
| 161 |
- Hover over nodes to see details
|
| 162 |
- Use the control panel (click the gear icon) to adjust physics settings
|
|
@@ -175,5 +194,8 @@ st.components.v1.html(html, height=800, scrolling=True)
|
|
| 175 |
|
| 176 |
# Show raw data
|
| 177 |
st.subheader("Award Data")
|
| 178 |
-
st.dataframe(
|
|
|
|
|
|
|
|
|
|
| 179 |
|
|
|
|
| 16 |
# Load data
|
| 17 |
@st.cache_data
|
| 18 |
def load_data():
|
| 19 |
+
award_df = pd.read_csv('award_cleaned.csv')
|
| 20 |
+
award_df_remove_amount = pd.read_csv('award_cleaned_remove_amount.csv')
|
| 21 |
+
faculty_college_df = pd.read_csv('faculty_college_jenny_manual.csv')
|
| 22 |
+
return award_df, award_df_remove_amount, faculty_college_df
|
| 23 |
|
| 24 |
|
| 25 |
+
award_df, award_df_remove_amount, faculty_college_df = load_data()
|
| 26 |
award_df.columns = award_df.columns.str.strip() # Clean column names
|
| 27 |
faculty_college_df = faculty_college_df.apply(lambda x: x.str.strip() if x.dtype == "object" else x)
|
| 28 |
|
|
|
|
| 42 |
# faculty_colleges = defaultdict(list)
|
| 43 |
faculty_amounts = defaultdict(float)
|
| 44 |
|
| 45 |
+
# colorblind_palette =[
|
| 46 |
+
# '#FF6B6B', '#4ECDC4', '#45B7D1', '#96CEB4',
|
| 47 |
+
# '#FFEEAD', '#D4A5A5', '#779ECB', '#FFB347',
|
| 48 |
+
# '#B1DDF3', '#A8E6CF', '#DCEDC1', '#FFD3B6',
|
| 49 |
+
# '#FFAAA5', '#C8C6A7', '#92967D'
|
| 50 |
+
# ]
|
| 51 |
+
|
| 52 |
+
colorblind_palette = [
|
| 53 |
+
'#E6194B', # Bright red
|
| 54 |
+
'#3CB44B', # Green
|
| 55 |
+
'#4363D8', # Blue
|
| 56 |
+
'#FFE119', # Yellow
|
| 57 |
+
'#911EB4', # Purple
|
| 58 |
+
'#F58231', # Orange
|
| 59 |
+
'#42D4F4', # Cyan
|
| 60 |
+
'#FABEBE' # Light pink
|
| 61 |
+
]
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
# colorblind_palette = [
|
| 65 |
+
# '#FF1E1E', '#00E5D0', '#00AAFF', '#7AFF86',
|
| 66 |
+
# '#FFDD00', '#FF7575', ''#8A2BE2', '#FF9500',
|
| 67 |
+
# '#83EAFF', '#59FFAA', '#BFFF59', '#FFB380',
|
| 68 |
+
# '#FF6666', '#E0FF4D', '#66FFC2'
|
| 69 |
+
# ]
|
| 70 |
|
| 71 |
for _, row in df.iterrows():
|
| 72 |
# Process PI information
|
|
|
|
| 122 |
college_colors[college] = colorblind_palette[i % len(colorblind_palette)]
|
| 123 |
|
| 124 |
# Add explicit color for Unknown
|
| 125 |
+
# college_colors['Unknown'] = '#888888'
|
| 126 |
# unique_colleges = sorted(list(set(college_map.values())))
|
| 127 |
# colormap = plt.cm.get_cmap('tab20', len(unique_colleges))
|
| 128 |
# college_colors = {college: to_hex(colormap(i)) for i, college in enumerate(unique_colleges)}
|
|
|
|
| 147 |
college = college_assignment.get(node, 'Unknown')
|
| 148 |
G.nodes[node]['color'] = college_colors.get(college_map.get(node, 'Unknown'), '#888888')
|
| 149 |
G.nodes[node]['size'] = node_sizes[i]
|
| 150 |
+
G.nodes[node]['title'] = (f"{node} | College: {college_map.get(node, 'Unknown')}")
|
|
|
|
| 151 |
|
| 152 |
return G, college_colors
|
| 153 |
|
|
|
|
| 175 |
st.markdown("""
|
| 176 |
**Network Interaction Guide:**
|
| 177 |
- Drag nodes to rearrange the network
|
| 178 |
+
- Scroll to zoom in/out to see the details: Faculty Name | College
|
| 179 |
- Click and drag background to pan
|
| 180 |
- Hover over nodes to see details
|
| 181 |
- Use the control panel (click the gear icon) to adjust physics settings
|
|
|
|
| 194 |
|
| 195 |
# Show raw data
|
| 196 |
st.subheader("Award Data")
|
| 197 |
+
st.dataframe(award_df_remove_amount, use_container_width=True)
|
| 198 |
+
|
| 199 |
+
st.subheader("Faculty Data")
|
| 200 |
+
st.dataframe(faculty_college_df, use_container_width=True)
|
| 201 |
|