{"id":287,"date":"2021-07-26T00:00:00","date_gmt":"2021-07-26T00:00:00","guid":{"rendered":"https:\/\/tac.debuzzify.com\/?p=287"},"modified":"2023-06-27T13:58:50","modified_gmt":"2023-06-27T13:58:50","slug":"how-to-create-stunning-web-apps-for-your-data-science-projects","status":"publish","type":"post","link":"https:\/\/www.the-analytics.club\/how-to-create-stunning-web-apps-for-your-data-science-projects\/","title":{"rendered":"How to Create Stunning Web Apps for Your Data Science Projects"},"content":{"rendered":"\n
Web development isn’t a data scientist’s core competency. Most data scientists don’t bother to learn different technologies to do it. It’s just not their cup of coffee.<\/p>\n\n\n\n
Yet, most data science projects also have a software development component. A web app for data science projects is a must at some point. Developers sometimes have a different understanding of the problem, and they use discrete technologies. It often causes problems and drains the precious time of both teams unproductively.<\/p>\n\n\n\n
Also, visualization tools such as Tableau and Power BI focus more on data exploration. Yet, it’s only part of a complete data science project. If you need to integrate a machine learning model, they are far from perfect.<\/p>\n\n\n\n
Streamlit<\/a> allows you to develop web apps for your data science projects. This open-source library’s API is entirely in Python. Hence you don’t have to learn any other web technology to use it. Also, it’s straightforward to learn and flexible for modifications.<\/p>\n\n\n\n This article is an introduction to Streamlit. We’ll build an interactive web app that takes user inputs, runs a K-means algorithm, and instantly plots the results in a web interface.<\/p>\n\n\n\n\n\n Here is the link<\/a> to the deployed version. Check it out if you want a sneak peek.<\/p>\n\n\n\n This extraordinary tool has an embarrassingly simple setup, and almost all Python users are familiar with it. Use PyPI.<\/p>\n\n\n\n You can also use conda<\/a> and other popular Python package managers.<\/p>\n\n\n\n Once completed, you can test it with a hello world app that comes with the installation. Execute the below command in a terminal window to start the development server.<\/p>\n\n\n\n The hello world app is a set of excellent visualization you can do with Streamlit. The above command will start a local development server and open the link in your default browser. You can also find the source codes on the same page. In addition, this sample app also has links to lots of advanced tutorials to educate yourself.<\/p>\n\n\n\n Now that the setup is complete, let’s create an app to interact with our machine-learning model.<\/p>\n\n\n\n The app below uses Pandas, Scikit-Learn, Matplotlib, Seaborn, and Streamlit. Before starting, make sure you have installed all the required packages. If not, the below command will do it for you.<\/p>\n\n\n\n Create a file named ‘quickstart.py’ with the below content.<\/p>\n\n\n\n The above file is straightforward. For illustration purposes, I’ve added sections to the file.<\/p>\n\n\n\n In the main app section, we have three lines. We added a title and a description to the page. Then we display the data frame on the page. The “st.write” function is an all-in-one solution. You could pass almost anything into this function, and Streamlit is smart enough to display the correct widget in the UI. To learn about different Streamlit functions, here is a cheat sheet<\/a>.<\/p>\n\n\n\n Let’s run our initial app with the below command.<\/p>\n\n\n\n Like the Hello app, this command will start a new development server. On your browser, you’ll see the below.<\/p>\n\n\nSetting up Streamlit for development.<\/h1>\n\n\n\n
pip install streamlit\n<\/code><\/pre>\n\n\n\n
streamlit hello\n<\/code><\/pre>\n\n\n\n
Using machine learning models with a Streamlit web app.<\/h1>\n\n\n\n
pip install pandas scikit-learn matplotlib seaborn streamlit\n<\/code><\/pre>\n\n\n\n
Creating your first web app for data science projects.<\/h2>\n\n\n\n
# Imports\n# -----------------------------------------------------------\nimport streamlit as st\nimport pandas as pd\n# -----------------------------------------------------------\n\n# Helper functions\n# -----------------------------------------------------------\n# Load data from external source\ndf = pd.read_csv(\n \"https:\/\/raw.githubusercontent.com\/ThuwarakeshM\/PracticalML-KMeans-Election\/master\/voters_demo_sample.csv\"\n)\n# -----------------------------------------------------------\n\n# Sidebar\n# -----------------------------------------------------------\n\n# -----------------------------------------------------------\n\n\n# Main\n# -----------------------------------------------------------\n# Create a title for your app\nst.title(\"Interactive K-Means Clustering\")\n\n# A description\nst.write(\"Here is the dataset used in this analysis:\")\n\n# Display the dataframe\nst.write(df)\n# -----------------------------------------------------------\n<\/code><\/pre>\n\n\n\n
streamlilt run quickstart.py\n<\/code><\/pre>\n\n\n\n