Posted in python

Streamlit: My recommended tool for data science app development

Streamlit is a web application framework that helps in the building and development of Python-based web applications to share data, build data dashboards, app development and even build machine learning models. In addition, developing and deploying Streamlit apps is amazingly quick and versatile, allowing the development of simple apps in a few hours. In fact, I was able to make a simple app within a day after reading this book:

Getting Started with Streamlit for Data Science | Packt
My favourite book for Streamlit

This book summarises the basics of Streamlit, and provides realistic solutions in executing python codes and simple app development. Streamlit is quite newly developed so there are very few books available to learn from. Nonetheless, from the examples provided in the book, I was able to make a simple scatterplot app. We can first load the dataset to make sure we are analysing the correct dataset:

The commands that make the above section are as follows:

st.title() # Gives the header title
st.markdown() # Can provide descriptions of the title in smaller fonts
st.file_uploader() # Creates a file uploader for users to drag and drop
st.write() # Loads the details of the dataset 

Next, we want to create widgets that allow users to select their x and y-axis variables:

To make the above section, the relevant commands are as follows:

st.selectbox() #To create widgets for users to select
px.scatter() # For plotting scatterplot with plotly express
plotly_chart() # To plot the figure out

Why use Plotly? This is because Plotly allows you to interact with the graph, including zoom in and zoom out functions, mousing over data points to determine data point attributes and selection functions to crop the range of x- and y-axis.

Deploying in Streamlit is fast, but the initial steps of setting up can be time-consuming, especially if this is the first time you are trying out. The essential steps are as follows:
1. Create a GitHub account
2. Contact the Streamlit Team to allow the developers to connect Streamlit to your GitHub account
3. Create the GitHub repository. You can choose to make a public or private repository. To make the requirements.txt file, make sure you download by typing the following command: pip install pipreqs.
4. Create apps within the Streamlit account by adding the Github repository address and specifying the Python file to execute.

And that’s it! Your web address will start with: https://share.streamlit.io and the deployed website can be shared publicly to anyone. Furthermore, any changes you make within the GitHub repository can be immediately updated into the deployed website. I appreciate the responsiveness and the speed of deploying the website once everything is set up. Finally, for an icing in the cake, you can even convert the weblink into a desktop app with these specific instructions! If you are into app development and you want to stick to the Python language, I would strongly recommend Streamlit. It’s simplicity from coding to execution and deployment is just so attractive!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s