Turn Your Excel File Into A Web App With Python (fast & easy) | Streamlit Tutorial
Language:
In this tutorial, I am going to show you how to convert Excel Files into a Web Application by using the Python Library Streamlit. The beauty of Streamlit is that you can create web applications directly in Python, without needing to know HTML, CSS, or JavaScript. The Web App is fully interactive and will be updated, whenever you make changes in the Excel file.
📝 Resources:
You can download all the files from the tutorial here:
Download Here
Deploy your Streamlit Application to Heroku for free:
Deploy Your Streamlit Web App on Heroku For Free (fast & easy)
Streamlit Documentation & App Gallery:
👩💻 Source Code:
import pandas as pd import streamlit as st import plotly.express as px from PIL import Image st.set_page_config(page_title='Survey Results') st.header('Survey Results 2021') st.subheader('Was the tutorial helpful?') ### --- LOAD DATAFRAME excel_file = 'Survey_Results.xlsx' sheet_name = 'DATA' df = pd.read_excel(excel_file, sheet_name=sheet_name, usecols='B:D', header=3) df_participants = pd.read_excel(excel_file, sheet_name= sheet_name, usecols='F:G', header=3) df_participants.dropna(inplace=True) # --- STREAMLIT SELECTION department = df['Department'].unique().tolist() ages = df['Age'].unique().tolist() age_selection = st.slider('Age:', min_value= min(ages), max_value= max(ages), value=(min(ages),max(ages))) department_selection = st.multiselect('Department:', department, default=department) # --- FILTER DATAFRAME BASED ON SELECTION mask = (df['Age'].between(*age_selection)) & (df['Department'].isin(department_selection)) number_of_result = df[mask].shape[0] st.markdown(f'*Available Results: {number_of_result}*') # --- GROUP DATAFRAME AFTER SELECTION df_grouped = df[mask].groupby(by=['Rating']).count()[['Age']] df_grouped = df_grouped.rename(columns={'Age': 'Votes'}) df_grouped = df_grouped.reset_index() # --- PLOT BAR CHART bar_chart = px.bar(df_grouped, x='Rating', y='Votes', text='Votes', color_discrete_sequence = ['#F63366']*len(df_grouped), template= 'plotly_white') st.plotly_chart(bar_chart) # --- DISPLAY IMAGE & DATAFRAME col1, col2 = st.beta_columns(2) image = Image.open('images/survey.jpg') print(image) col1.image(image, caption='Designed by slidesgo / Freepik', use_column_width=True) col2.dataframe(df[mask]) # --- PLOT PIE CHART pie_chart = px.pie(df_participants, title='Total No. of Participants', values='Participants', names='Departments') st.plotly_chart(pie_chart)