dhrumii commited on
Commit
4bfe684
·
verified ·
1 Parent(s): 79610e0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -321,17 +321,20 @@ def fuel_norm_distribution_dashboard(root_dir, state_mapping_file, start_year=20
321
  # Download button
322
  st.markdown("### 📥 Download Filtered Data")
323
 
 
324
  output = BytesIO()
325
  with pd.ExcelWriter(output, engine='xlsxwriter') as writer:
326
  filtered_df.to_excel(writer, index=False, sheet_name="Filtered Data")
 
327
 
 
328
  st.download_button(
329
  label="Download Excel",
330
  data=output.getvalue(),
331
  file_name="fuel_distribution_filtered.xlsx",
332
  mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
333
- )formats-officedocument.spreadsheetml.sheet")
334
-
335
 
336
  with tab2:
337
  st.subheader("Emission Norm Distribution by State")
@@ -353,14 +356,14 @@ def fuel_norm_distribution_dashboard(root_dir, state_mapping_file, start_year=20
353
  st.plotly_chart(fig2, use_container_width=True)
354
 
355
  # Download button
356
- st.markdown("### 📥 Download Filtered Norms Data")
357
-
358
  norm_output = BytesIO()
359
  with pd.ExcelWriter(norm_output, engine='xlsxwriter') as writer:
360
  filtered_norms.to_excel(writer, index=False, sheet_name="Filtered Norms")
 
361
 
362
  st.download_button(
363
- label="Download Excel",
364
  data=norm_output.getvalue(),
365
  file_name="norm_distribution_filtered.xlsx",
366
  mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
 
321
  # Download button
322
  st.markdown("### 📥 Download Filtered Data")
323
 
324
+ # Create an in-memory Excel file
325
  output = BytesIO()
326
  with pd.ExcelWriter(output, engine='xlsxwriter') as writer:
327
  filtered_df.to_excel(writer, index=False, sheet_name="Filtered Data")
328
+ output.seek(0) # Move to the beginning of the stream
329
 
330
+ # Download button for Excel
331
  st.download_button(
332
  label="Download Excel",
333
  data=output.getvalue(),
334
  file_name="fuel_distribution_filtered.xlsx",
335
  mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
336
+ )
337
+
338
 
339
  with tab2:
340
  st.subheader("Emission Norm Distribution by State")
 
356
  st.plotly_chart(fig2, use_container_width=True)
357
 
358
  # Download button
359
+ # 📥 Download button for filtered norms data (Excel only)
 
360
  norm_output = BytesIO()
361
  with pd.ExcelWriter(norm_output, engine='xlsxwriter') as writer:
362
  filtered_norms.to_excel(writer, index=False, sheet_name="Filtered Norms")
363
+ norm_output.seek(0)
364
 
365
  st.download_button(
366
+ label="Download Filtered Norms Data",
367
  data=norm_output.getvalue(),
368
  file_name="norm_distribution_filtered.xlsx",
369
  mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"