How to Upload Exe as a Web Application

The Streamlit Series

Present your excel spreadsheet equally an interactive dashboard spider web application using the python library Streamlit

Photo by Matheus Bertelli from Pexels

What is Streamlit?

Streamlit is an open up-source Python library that makes information technology easy to create and share beautiful, custom web apps for machine learning and data science projects [one]

1 of the principal features of Streamlit is information technology provides you lot a Jupyter Notebook-like environment where your lawmaking is updated live as you save your script. This helps a lot, particularly for the initial app development stage.

Prototype from Streamlit.io. GIF by Author

Trouble with Excels and Data Science Projects

The trouble that exists with excel and data science projects is the lack of an easy fashion to present the results (a.k.a production deployment). For an excel file to be presented, y'all volition either need to link information technology with visualization tools such as Power BI, Tableau, or Powerpoint.

Whereas for a data science project to exist implemented, you will need to implement a backend server such as Django, Flask, and a front-end UI such equally React and Vue.js.

These complications make data sharing with excels and data science projects extremely Boring and TEDIOUS.

Luckily with the assistance of Streamlit, we can easily create an interactive web awarding out of Excel spreadsheets and deploy information science projects easily. 🙌

At the finish of this commodity, yous will be able to create an interactive excel dashboard web application which enable user to filter the information, visualize graph and access hands using URL. Alternatively, y'all tin can visit the web application here and the repository here

Interactive excel dashboard. Image by Writer

Getting started:

We will exist using the World Happiness Report 2021 from Kaggle as our dataset for this article, feel free to download information technology below:

Install Streamlit via pip install

          pip install streamlit        

Verify your install via blazon in Streamlit CLI in control prompt

          streamlit how-do-you-do        

That's it! In the side by side few seconds, the sample app will open in a new tab in your default browse.

To brand your own apps, create a bare python file app.py, and run it with streamlit CLI. Then, click the localhost URL to enter your first streamlit spider web apps!

          streamlit run app.py        

Starting up streamlit spider web app. Epitome by Author

Understanding the UI

Past default Streamlit already have 2 places to put your code and widget in, which are the sidebar and content. You lot tin can add together elements and widget in the content area simply using:

          import streamlit as st
st.[element_name]

Y'all can add elements and widget in the sidebar simply using:

          import streamlit every bit st
st.sidebar.[element_name]

You lot can put any chemical element in the sidebar as per content area, the only elements that aren't supported are st.echo and st.spinner at the fourth dimension of writing.

Area of Streamlit App. Prototype by author

Load the data

Loading data from Excel and CSV can be done using pandas:

          import pandas as pd          #For Excel File
df = pd.read_excel("world-happiness-report-2021.xlxs")
#For CSV File
df = pd.read_csv("world-happiness-written report-2021.csv")

Display Widget

Display widget is pretty straightforward, you want a Text, merely write information technology equally:

          st.championship("Globe Happiness Index 2021:")        

If y'all want it to appear in the sidebar, just write the code equally:

          st.sidebar.title("World Happiness Index 2021:")        

If you want an image, just write:

          st.paradigm("https://images.pexels.com/photos/573259/pexels-photograph-573259.jpeg?cs=srgb&dl=pexels-matheus-bertelli-573259.jpg&fm=jpg", caption='World Happiness Dataset')        

If yous want to display a data frame, only write:

          st.write(filtered_df)        

Printed Data Frame. Image by Writer

That'south how unproblematic it works in Streamlit!

Controller Widget

Streamlit has a "Country-like" component function where the interaction of the user with the widget will change the state of the variable. Then, the new value of the variable will be used to rerender the components of the whole project.

In this project, nosotros will create a select box widget that can be used to filter the land and a slider to filter the ladder score in the sidebar every bit an example.

                      #Country Select Filter            
country_list = ["All","Western Europe", "South Asia", "Southeast Asia", "East asia", "Northward America and ANZ","Middle East and N Africa", "Latin America and Caribbean area","Central and Eastern Europe","Republic of Independent States","Sub-Saharan Africa"]
select = st.sidebar.selectbox('Filter the region hither:', country_list, key='1') if select =="All":
filtered_df = df
else:
filtered_df = df[df['Regional indicator']==select]
#Ladder Score Slider
score = st.sidebar.slider('Select min Ladder Score', min_value=five, max_value=10, value = 10) # Getting the input.
df = df[df['Ladder score'] <= score] # Filtering the dataframe.

Y'all will go the widget that can filter the information frame as below:

Controller widget. Image by Writer

Visualization Widget

Streamlit supports several dissimilar charting libraries such as Matplotlib, Seaborns, Ploty, Altair charts. It also provides a few native charts such as line nautical chart and surface area nautical chart which can be called past a line of lawmaking, for example:

                      #Line Chart            
st.line_chart (data=None, width=0, summit=0, use_container_width=True)
#Area Nautical chart
st.area_chart (data=None, width=0, height=0, use_container_width=True)

All the same, in this tutorial, nosotros will be using Plotly express for the scatter chart and bar chart. Then, nosotros use seaborn for the heatmap chart as below:

          import plotly.limited every bit px
import seaborn as sns
#Scatter Chart
fig = px.scatter(filtered_df,
x="Logged GDP per capita",
y="Salubrious life expectancy",
size="Ladder score",
colour="Regional indicator",
hover_name="Country proper name",
size_max=10)
st.write(fig) #Bar Chart, you can write in this style as well
st.write(px.bar(filtered_df, y='Ladder score', ten='Country name'))
#Seaborn Heatmap
#correlate data
corr = filtered_df.corr()
#using matplotlib to ascertain the size
plt.effigy(figsize=(8, 8))
#creating the heatmap with seaborn
fig1 = plt.figure()
ax = sns.heatmap(corr,
vmin=-1, vmax=ane, center=0,
cmap=sns.diverging_palette(20, 220, north=200),
square=True
)
ax.set_xticklabels(
ax.get_xticklabels(),
rotation=45,
horizontalalignment='right'
);
st.pyplot(fig1)

Notation: Notice that for Seaborn it is an axes component, then you cannot directly apply st.write to render the chart, whereas you must use st.pyplot to return the components.

Deployment via Streamlit Sharing

Streamlit has another unique feature chosen streamlit sharing, where they assist you to host your streamlit app on their website. Simply prepare a requirements.txt file in the same folder as app.py volition do the magic.

The requirements.txt file tells the system what python parcel the app volition be using, in our case, it volition exist:

          streamlit==0.83.0
numpy==1.xviii.5
pandas==ane.ii.4
matplotlib==3.4.2
plotly-express==0.four.one
seaborn==0.11.1

Click deploy and you lot will get the URL of your web apps. 🎉🎉

Streamlit Sharing deployment Sharing. Image by Author.

*At the time of writing, Streamlit Sharing required an invitation from Streamlit. Information technology took around 2 working days for them to approve my account

Deployment via Heroku

Alternative to the recommended feature, you can host your apps at Heroku or any other custom host like digital ocean, AWS, or google deject. I volition bear witness the method of hosting in Heroku as it is a Costless solution.

To host in Heroku, y'all will need the exact same requirement.txt as above in the exact aforementioned location. Besides that, you volition need 2 additional files which are:

a) Procfile:

          web: sh setup.sh && streamlit run app.py        

b) setup.sh:

          mkdir -p ~/.streamlit/          echo "\
[general]\due north\
email = \"<youremail>\"\n\
" > ~/.streamlit/credentials.toml
echo "\
[server]\due north\
headless = true\n\
port = $PORT\n\
enableCORS = simulated\n\
\n\
" > ~/.streamlit/config.toml

Re-create exactly the aforementioned setup every bit in a higher place and you will have the binder structure every bit below:

Project folder construction. Image by Author

I had hosted the same project both in Heroku and Streamlit Sharing, you tin can check on it and compare the speed and functionality yourself. In my opinion, both ways take their pro and cons, Streamlit Sharing offers free hosting and Hosting in Heroku have a limitation of ii Gratis hosting per account.

Concluding Thought

In this article, we had covered the basics of Streamlit which include installation, the bones concept of scripting in Streamlit, dashboard design, chart visualization, and deployment of the spider web app.

Streamlit is a new paradigm of data presentation tools that have enormous potential. It solves the terminal-mile problem in information science which is to evangelize the project easily to end-users regardless of layman or peer data scientist. It took me less than ane hour to understand the Streamlit concept and fall in ❤️ with information technology, I promise my sharing can spark your interest in Streamlit too!

Lastly, Thank you very much for reading my article.

Side notes:

Here's a video to innovate what is Streamlit in under 100 seconds:

Streamlit in 100 seconds

If you are interested in excel automation, this article is a must-read:

My other manufactures included:

References:

[1] https://streamlit.io

[2] https://doc.streamlit.io/

mccrorysnest1956.blogspot.com

Source: https://towardsdatascience.com/turn-excel-into-a-beautiful-web-application-using-streamlit-7a18516ca01a

0 Response to "How to Upload Exe as a Web Application"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel