Roberta2024 commited on
Commit
0ea303d
·
verified ·
1 Parent(s): b112582

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -9
app.py CHANGED
@@ -78,7 +78,7 @@ def fetch_data():
78
  new_row = pd.DataFrame({
79
  "Store Name": [store_name],
80
  "Address": [address],
81
- "Phone": [phone], # Add phone number to the DataFrame
82
  "Latitude": [latitude],
83
  "Longitude": [longitude],
84
  "Region": [region]
@@ -93,7 +93,7 @@ def fetch_data():
93
  if st.button("Fetch Restaurant Data"):
94
  fetch_data()
95
 
96
- # Save the DataFrame to CSV with UTF-8 encoding
97
  csv_file = "restaurants_data.csv"
98
  df.to_csv(csv_file, encoding="utf-8-sig", index=False)
99
 
@@ -105,26 +105,39 @@ if st.button("Fetch Restaurant Data"):
105
  mime="text/csv"
106
  )
107
 
108
- # Group the data by region
109
  region_group = df.groupby("Region").size().reset_index(name='Count')
110
 
111
- # Plot pie chart
112
  pie_chart = go.Figure(go.Pie(
113
  labels=region_group["Region"],
114
  values=region_group["Count"],
115
- hoverinfo="label+percent",
116
- textinfo="value+percent",
 
 
117
  ))
118
- st.subheader("Restaurant Distribution by Region (Pie Chart)")
 
 
 
 
 
119
  st.plotly_chart(pie_chart)
120
 
121
- # Plot bar chart
122
  bar_chart = go.Figure(go.Bar(
123
  x=region_group["Region"],
124
  y=region_group["Count"],
125
  text=region_group["Count"],
126
  textposition='auto'
127
  ))
 
 
 
 
 
 
128
  st.subheader("Restaurant Count by Region (Bar Chart)")
129
  st.plotly_chart(bar_chart)
130
 
@@ -140,7 +153,7 @@ if st.button("Fetch Restaurant Data"):
140
  if pd.notnull(row["Latitude"]) and pd.notnull(row["Longitude"]):
141
  folium.Marker(
142
  location=[row["Latitude"], row["Longitude"]],
143
- popup=f"{row['Store Name']} ({row['Phone']})", # Show phone in the popup
144
  tooltip=row["Address"]
145
  ).add_to(marker_cluster)
146
 
 
78
  new_row = pd.DataFrame({
79
  "Store Name": [store_name],
80
  "Address": [address],
81
+ "Phone": [phone],
82
  "Latitude": [latitude],
83
  "Longitude": [longitude],
84
  "Region": [region]
 
93
  if st.button("Fetch Restaurant Data"):
94
  fetch_data()
95
 
96
+ # Save the DataFrame to CSV with UTF-8 encoding, including latitude and longitude
97
  csv_file = "restaurants_data.csv"
98
  df.to_csv(csv_file, encoding="utf-8-sig", index=False)
99
 
 
105
  mime="text/csv"
106
  )
107
 
108
+ # Group the data by region and sum the number of restaurants
109
  region_group = df.groupby("Region").size().reset_index(name='Count')
110
 
111
+ # Plot enlarged pie chart with store names
112
  pie_chart = go.Figure(go.Pie(
113
  labels=region_group["Region"],
114
  values=region_group["Count"],
115
+ textinfo="label+percent", # Include region and percentage
116
+ hoverinfo="label+value", # Show region and count on hover
117
+ textfont=dict(size=18), # Make text larger
118
+ marker=dict(line=dict(color='#000000', width=2)) # Add a border to slices
119
  ))
120
+
121
+ pie_chart.update_layout(
122
+ height=600, # Increase the size of the chart
123
+ margin=dict(t=0, b=0, l=0, r=0)
124
+ )
125
+ st.subheader("Restaurant Distribution by Region (Enlarged Pie Chart)")
126
  st.plotly_chart(pie_chart)
127
 
128
+ # Plot bar chart with store counts
129
  bar_chart = go.Figure(go.Bar(
130
  x=region_group["Region"],
131
  y=region_group["Count"],
132
  text=region_group["Count"],
133
  textposition='auto'
134
  ))
135
+
136
+ bar_chart.update_layout(
137
+ height=400,
138
+ margin=dict(t=50, b=50, l=50, r=50),
139
+ title="Restaurant Count by Region"
140
+ )
141
  st.subheader("Restaurant Count by Region (Bar Chart)")
142
  st.plotly_chart(bar_chart)
143
 
 
153
  if pd.notnull(row["Latitude"]) and pd.notnull(row["Longitude"]):
154
  folium.Marker(
155
  location=[row["Latitude"], row["Longitude"]],
156
+ popup=f"{row['Store Name']} ({row['Phone']})",
157
  tooltip=row["Address"]
158
  ).add_to(marker_cluster)
159