|
55 | 55 |
|
56 | 56 | calculate = st.sidebar.button("Calculate Centers", type="primary", use_container_width=True)
|
57 | 57 |
|
| 58 | +school_df = None |
58 | 59 | # Tabs
|
59 | 60 | tab1, tab2, tab3, tab4, tab5 = st.tabs([
|
60 | 61 | "School Center",
|
|
73 | 74 | # Show data in Tabs as soon as the files are uploaded
|
74 | 75 | if schools_file:
|
75 | 76 | df = pd.read_csv(schools_file, sep="\t")
|
| 77 | + school_df = df |
76 | 78 | tab3.dataframe(df)
|
| 79 | + |
77 | 80 | else:
|
78 | 81 | tab3.info("Upload data to view it.", icon="ℹ️")
|
79 | 82 |
|
@@ -193,9 +196,37 @@ def save_file_to_temp(file_obj):
|
193 | 196 | icon=folium.Icon(color="red")
|
194 | 197 | )
|
195 | 198 | )
|
| 199 | + |
| 200 | + # Initialize an empty dictionary to store school coordinates |
| 201 | + filtered_schools = {} |
| 202 | + |
| 203 | + if school_df is not None: |
| 204 | + |
| 205 | + for index, row in school_df.iterrows(): |
| 206 | + scode = row['scode'] |
| 207 | + school_lat = row['lat'] |
| 208 | + school_long = row['long'] |
| 209 | + |
| 210 | + if scode in filtered_df['scode'].values: |
| 211 | + filtered_schools.setdefault(scode, []).append((school_lat, school_long)) |
| 212 | + |
| 213 | + for index, school in filtered_df.iterrows(): |
| 214 | + lat_long_list = filtered_schools.get(school['scode'], []) |
| 215 | + |
| 216 | + for school_lat, school_long in lat_long_list: |
| 217 | + if school_lat is not None and school_long is not None: |
| 218 | + fg.add_child( |
| 219 | + folium.Marker( |
| 220 | + location=[school_lat, school_long], |
| 221 | + popup=f"{school['school'].title()}\nAllocation: {school['allocation']}", |
| 222 | + tooltip=f"{school['school']}", |
| 223 | + icon=folium.Icon(color="blue") |
| 224 | + ) |
| 225 | + ) |
| 226 | + |
196 | 227 | m.add_child(fg)
|
197 | 228 | with tab1:
|
198 |
| - st_folium( m, width=1200, height=400 ) |
| 229 | + st_folium( m, width=1200, height=400) |
199 | 230 |
|
200 | 231 | tab1.divider()
|
201 | 232 | tab1.subheader('All Data')
|
|
0 commit comments