Corgi working on a Data Science project. 2023. Roman x Stable Diffusion XL
Streamlit has rapidly become a go-to tool for data scientists and developers wanting to turn data scripts into shareable web apps. Let’s explore its core features and benefits:
@st.cache
, Streamlit caches the output of functions, ensuring your data operations are efficient and your apps remain performant.While Streamlit offers a robust platform for creating web apps, Gradio provides several distinct advantages, especially when the focus is on deploying machine learning models:
These unique features make Gradio an attractive option for projects that focus on deploying and sharing machine learning models with diverse requirements. We are going to explore gradio after introductions to ML.
st.columns
and st.container
can be used to design your app’s layout.st.slider()
, st.selectbox()
, and st.button()
that capture user input.st.image()
, st.video()
, and st.audio()
.st.line_chart()
, st.bar_chart()
, or integrate with libraries like Altair for custom visualizations.st.table()
or st.dataframe()
.st.session_state
.To truly master Streamlit, it’s recommended to experiment with building various apps and exploring its official documentation. The community is active, and there’s always something new to learn!
By the end of this tutorial, you’ll have a functional dashboard that allows users to:
Before you begin, ensure you have the following:
pip install streamlit
).altair
, matplotlib
, and seaborn
.We’ll use a synthetic dataset on employee attrition from this link.
Ensure your working directory has the following structure:
📦Your_Directory
┣ 📜app.py
┗ 📜requirements.txt
┗ 📜data.csv
app.py
will contain our Streamlit app’s code, while requirements.txt
will list the necessary Python packages.
Once you’ve built the app, we’ll first host it on Streamlit Cloud and then on uCloud (A Danish private cloud for universities).
Here is the code
We start by importing necessary libraries and loading our dataset. The data is cached using @st.cache_data
to enhance performance.
Streamlit provides intuitive functions to design the user interface:
st.title()
and st.header()
set titles and headers.st.markdown()
allows for rich text formatting.st.sidebar
lets you add interactive widgets in a sidebar for filtering.Depending on user input, we visualize the filtered data using various charts. For instance, altair
is used for bar and pie charts, while matplotlib
and seaborn
provide KDE plots and boxplots.
Finally, expanders provide a space to share insights derived from visualizations and actionable recommendations.
You can access the final deployed Employee Attrition Dashboard on Streamlit using the link below:
Feel free to explore the app, interact with the various filters and visualizations, and gain insights into employee attrition patterns.
Streamlit offers a user-friendly platform to build and deploy interactive data apps without the need for extensive web development skills. Dive in, explore the code, and customize it to create your own data-driven web applications.
Happy Coding! 🚀
Corgi working on a Data Science project. 2022. Roman x Stable Diffusion