├── Data.xlsx
├── README.md
├── app.py
└── requirements.txt
/Data.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sven-Bo/streamlit-excel-plotter-app/cf0ea58696db4e6b70d9bac22b9e4b815d09c218/Data.xlsx
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | # Build a Web App to Group & Plot Excel Files in Python with Streamlit
3 |
4 | Did you know that you can quickly develop web applications in just a few lines of code using Python? Streamlit is a Python module that makes it very easy to quickly develop web apps. In this particular web app, we will be transforming & visualizing Excel files. Once the data has been grouped, the user can download the interactive chart and the corresponding Excel workbook.
5 |
6 |
7 | ## Video Tutorial
8 |
9 | [](https://youtu.be/ZDffoP6gjxc)
10 |
11 |
12 |
13 | ## 🤓 Check Out My Excel Add-ins
14 | I've developed some handy Excel add-ins that you might find useful:
15 |
16 | - 📊 **[Dashboard Add-in](https://pythonandvba.com/grafly)**: Easily create interactive and visually appealing dashboards.
17 | - 🎨 **[Cartoon Charts Add-In](https://pythonandvba.com/cuteplots)**: Create engaging and fun cartoon-style charts.
18 | - 🤪 **[Emoji Add-in](https://pythonandvba.com/emojify)**: Add a touch of fun to your spreadsheets with emojis.
19 | - 🛠️ **[MyToolBelt Add-in](https://pythonandvba.com/mytoolbelt)**: A versatile toolbelt for Excel, featuring:
20 | - Creation of Pandas DataFrames and Jupyter Notebooks from Excel ranges
21 | - ChatGPT integration for advanced data analysis
22 | - And much more!
23 |
24 |
25 |
26 | ## 🤝 Connect with Me
27 | - 📺 **YouTube:** [CodingIsFun](https://youtube.com/c/CodingIsFun)
28 | - 🌐 **Website:** [PythonAndVBA](https://pythonandvba.com)
29 | - 💬 **Discord:** [Join the Community](https://pythonandvba.com/discord)
30 | - 💼 **LinkedIn:** [Sven Bosau](https://www.linkedin.com/in/sven-bosau/)
31 | - 📸 **Instagram:** [sven_bosau](https://www.instagram.com/sven_bosau/)
32 |
33 | ## ☕ Support
34 | If you appreciate the project and wish to encourage its continued development, consider [supporting my work](https://pythonandvba.com/coffee-donation).
35 | [](https://pythonandvba.com/coffee-donation)
36 |
37 | ## Feedback & Collaboration
38 | For feedback, suggestions, or potential collaboration opportunities, reach out at contact@pythonandvba.com.
39 | 
40 |
--------------------------------------------------------------------------------
/app.py:
--------------------------------------------------------------------------------
1 | import streamlit as st # pip install streamlit
2 | import pandas as pd # pip install pandas
3 | import plotly.express as px # pip install plotly-express
4 | import base64 # Standard Python Module
5 | from io import StringIO, BytesIO # Standard Python Module
6 |
7 |
8 | def generate_excel_download_link(df):
9 | # Credit Excel: https://discuss.streamlit.io/t/how-to-add-a-download-excel-csv-function-to-a-button/4474/5
10 | towrite = BytesIO()
11 | df.to_excel(towrite, encoding="utf-8", index=False, header=True) # write to BytesIO buffer
12 | towrite.seek(0) # reset pointer
13 | b64 = base64.b64encode(towrite.read()).decode()
14 | href = f'Download Excel File'
15 | return st.markdown(href, unsafe_allow_html=True)
16 |
17 | def generate_html_download_link(fig):
18 | # Credit Plotly: https://discuss.streamlit.io/t/download-plotly-plot-as-html/4426/2
19 | towrite = StringIO()
20 | fig.write_html(towrite, include_plotlyjs="cdn")
21 | towrite = BytesIO(towrite.getvalue().encode())
22 | b64 = base64.b64encode(towrite.read()).decode()
23 | href = f'Download Plot'
24 | return st.markdown(href, unsafe_allow_html=True)
25 |
26 |
27 | st.set_page_config(page_title='Excel Plotter')
28 | st.title('Excel Plotter 📈')
29 | st.subheader('Feed me with your Excel file')
30 |
31 | uploaded_file = st.file_uploader('Choose a XLSX file', type='xlsx')
32 | if uploaded_file:
33 | st.markdown('---')
34 | df = pd.read_excel(uploaded_file, engine='openpyxl')
35 | st.dataframe(df)
36 | groupby_column = st.selectbox(
37 | 'What would you like to analyse?',
38 | ('Ship Mode', 'Segment', 'Category', 'Sub-Category'),
39 | )
40 |
41 | # -- GROUP DATAFRAME
42 | output_columns = ['Sales', 'Profit']
43 | df_grouped = df.groupby(by=[groupby_column], as_index=False)[output_columns].sum()
44 |
45 | # -- PLOT DATAFRAME
46 | fig = px.bar(
47 | df_grouped,
48 | x=groupby_column,
49 | y='Sales',
50 | color='Profit',
51 | color_continuous_scale=['red', 'yellow', 'green'],
52 | template='plotly_white',
53 | title=f'Sales & Profit by {groupby_column}'
54 | )
55 | st.plotly_chart(fig)
56 |
57 | # -- DOWNLOAD SECTION
58 | st.subheader('Downloads:')
59 | generate_excel_download_link(df_grouped)
60 | generate_html_download_link(fig)
61 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | plotly==4.14.3
2 | pandas==1.2.0
3 | openpyxl==3.0.6
4 | streamlit==0.74.1
5 |
--------------------------------------------------------------------------------