fschwartzer commited on
Commit
e7d9cc7
·
1 Parent(s): 2506d4a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -7
app.py CHANGED
@@ -10,6 +10,7 @@ import folium
10
  from branca.colormap import LinearColormap
11
  import base64
12
 
 
13
  # Function to add heatmap layer to folium map
14
  def add_heatmap_layer(map_obj, data, column_name, colormap_name, radius=15):
15
  heat_data = data[['latitude', 'longitude', column_name]].dropna()
@@ -258,13 +259,25 @@ with st.container():
258
  st.map(filtered_data, zoom=zoom_level, use_container_width=True)
259
  st.write("Dados:", filtered_data) # Debug: Print filtered_data
260
 
261
- if st.button("Baixar arquivo do Excel"):
262
- with st.spinner('Downloading...'):
263
- excel_file = filtered_data.to_excel("filtered_data.xlsx", index=False)
264
- # Create a download link
265
- b64 = base64.b64encode(excel_file.encode()).decode()
266
- href = f'<a href="data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,{b64}" download="sample_data.xlsx">Download Excel File</a>'
267
- st.markdown(href, unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
268
 
269
  folium_layermap = folium.Map(location=[custom_lat, custom_lon], zoom_start=zoom_level, control_scale=True)
270
 
 
10
  from branca.colormap import LinearColormap
11
  import base64
12
 
13
+
14
  # Function to add heatmap layer to folium map
15
  def add_heatmap_layer(map_obj, data, column_name, colormap_name, radius=15):
16
  heat_data = data[['latitude', 'longitude', column_name]].dropna()
 
259
  st.map(filtered_data, zoom=zoom_level, use_container_width=True)
260
  st.write("Dados:", filtered_data) # Debug: Print filtered_data
261
 
262
+ if st.button('baixar EXCEL'):
263
+ st.write("Baixando...")
264
+ # Set up the file to be downloaded
265
+ output_df = filtered_data
266
+
267
+ # Create a BytesIO buffer to hold the Excel file
268
+ excel_buffer = BytesIO()
269
+
270
+ # Convert DataFrame to Excel and save to the buffer
271
+ with pd.ExcelWriter(excel_buffer, engine="xlsxwriter") as writer:
272
+ output_df.to_excel(writer, index=False, sheet_name="Sheet1")
273
+
274
+ # Reset the buffer position to the beginning
275
+ excel_buffer.seek(0)
276
+
277
+ # Create a download link
278
+ b64 = base64.b64encode(excel_buffer.read()).decode()
279
+ href = f'<a href="data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,{b64}" download="sample_data.xlsx">Download Excel File</a>'
280
+ st.markdown(href, unsafe_allow_html=True)
281
 
282
  folium_layermap = folium.Map(location=[custom_lat, custom_lon], zoom_start=zoom_level, control_scale=True)
283