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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -21
app.py CHANGED
@@ -13,6 +13,8 @@ import plotly.express as px
13
  import json
14
  from difflib import get_close_matches
15
  from xlsxwriter import Workbook
 
 
16
 
17
 
18
 
@@ -318,16 +320,18 @@ def fuel_norm_distribution_dashboard(root_dir, state_mapping_file, start_year=20
318
 
319
  # Download button
320
  st.markdown("### 📥 Download Filtered Data")
321
- download_format = st.radio("Select format", ["CSV", "Excel"], horizontal=True)
322
- if download_format == "CSV":
323
- csv_data = filtered_df.to_csv(index=False).encode("utf-8")
324
- st.download_button("Download CSV", csv_data, file_name="fuel_distribution_filtered.csv", mime="text/csv")
325
- else:
326
- output = BytesIO()
327
- with pd.ExcelWriter(output, engine='xlsxwriter') as writer:
328
- filtered_df.to_excel(writer, index=False, sheet_name="Filtered Data")
329
- st.download_button("Download Excel", output.getvalue(), file_name="fuel_distribution_filtered.xlsx", mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
330
-
 
 
331
 
332
  with tab2:
333
  st.subheader("Emission Norm Distribution by State")
@@ -349,17 +353,18 @@ def fuel_norm_distribution_dashboard(root_dir, state_mapping_file, start_year=20
349
  st.plotly_chart(fig2, use_container_width=True)
350
 
351
  # Download button
352
- st.markdown("### 📥 Download Filtered Norms Data")
353
- download_format_norms = st.radio("Select format", ["CSV", "Excel"], horizontal=True, key="norm_download_format")
354
- if download_format_norms == "CSV":
355
- csv_norm_data = filtered_norms.to_csv(index=False).encode("utf-8")
356
- st.download_button("Download CSV", csv_norm_data, file_name="norm_distribution_filtered.csv", mime="text/csv")
357
- else:
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
- st.download_button("Download Excel", norm_output.getvalue(), file_name="norm_distribution_filtered.xlsx", mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
362
-
 
363
  with tab3:
364
  st.subheader("Norm Emissions by Fuel Type and Year")
365
 
 
13
  import json
14
  from difflib import get_close_matches
15
  from xlsxwriter import Workbook
16
+ import io
17
+
18
 
19
 
20
 
 
320
 
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
  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"
367
+ )
368
  with tab3:
369
  st.subheader("Norm Emissions by Fuel Type and Year")
370