Skip to content

Commit 6dc5e32

Browse files
nirmala-sharmanirmala.sharma
andauthored
#84 Fixes of Schools are not plotted in map in streamlit app (#90)
* Fixes of Schools are not plotted in map in streamlit app * Fetch Schools Latitude,Logitude from session rather than fetching data from given school's sample_data * Use School List instead of fetching lat,long,scode from school-center-distance and use dataframe in tab3 instead of re-reading from tsv file --------- Co-authored-by: nirmala.sharma <[email protected]>
1 parent 4701ccf commit 6dc5e32

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

app.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555

5656
calculate = st.sidebar.button("Calculate Centers", type="primary", use_container_width=True)
5757

58+
school_df = None
5859
# Tabs
5960
tab1, tab2, tab3, tab4, tab5 = st.tabs([
6061
"School Center",
@@ -73,7 +74,9 @@
7374
# Show data in Tabs as soon as the files are uploaded
7475
if schools_file:
7576
df = pd.read_csv(schools_file, sep="\t")
77+
school_df = df
7678
tab3.dataframe(df)
79+
7780
else:
7881
tab3.info("Upload data to view it.", icon="ℹ️")
7982

@@ -193,9 +196,37 @@ def save_file_to_temp(file_obj):
193196
icon=folium.Icon(color="red")
194197
)
195198
)
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+
196227
m.add_child(fg)
197228
with tab1:
198-
st_folium( m, width=1200, height=400 )
229+
st_folium( m, width=1200, height=400)
199230

200231
tab1.divider()
201232
tab1.subheader('All Data')

0 commit comments

Comments
 (0)