How To Use The WordPress Debug Log

Do you ever make mistakes? I do. The first step to fixing your mistakes is knowing what the mistake is. I can’t solve all of your problems, but I can help fix those that are generated by PHP code on…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Web Application in 10 minutes with Streamlit

In this article, I will introduce Streamlit, my favorite web application library for Python. It allows you to create beautiful Data Science or Machine Learning (or maybe some other) applications in a blink of an eye.

Showing data applications to your colleagues or friends who are not aware of coding can be a tricky thing. Most of the people outside of the industry do not know how to input their values into the machine learning pipeline or generate the graph using the provided code. It is the case in which you need to develop the app and UI to make your findings available to everyone. However, most data scientists and machine learning engineers don’t know how to create a web app themselves.

As you can see, Amin’s app is quite advanced and can be used by a person who knows nothing about how the classification works. He can just upload the image and see the result!

Firstly, you need to install Streamlit. You can do this with PIP by running the following command in the terminal:

There may be problems with your Python version, so be sure to install Streamlit into Python 3.6+.

To create the app, you need to import Streamlit into your Python file and use a specific command in the terminal.

Then, we put the following commands into terminal:

When you run these commands, the app appears in your browser, and you can continue building it in real-time because the changes in your Python file will automatically appear on your app page (just use rerun in the app settings to see these changes).

I will build a very artificial app with no specific purpose to show you different features in Streamlit. Essentialy, will create a form to ask the user some inputs.

Let’s look at the app that we have right now from the previous step.

Now, it is a fully empty app; however, in this article we will fill it with elements.

Let’s add the title and description to our form. To do so, we will write the following code:

Now, our app looks like this. With st.write() method, you can write text anywhere in the application (also, it can be used for different graphs (plotly, altair, etc.) and other content).

Now, App has a Title and a Description

Text

One more detail: we need to save inputs in the variables to use later!

Numbers

App with Numeric Input

Dates

Sometimes, you need to ask a person for a date. It can be pretty hard to make the date format universal after collecting the free form format dates. Therefore, it is better to use a specific widget for that. You can also set minimum and maximum dates.

App with Date Input

Checkboxes and Radio Buttons

Let’s add other popular input types: checkboxes and radio buttons.

The check box can be added using st.checkbox() method. The return from this input is either True (if a person checked the box) or False.

The radio buttons can be added with the method st.radio(). You need to provide options for this type of input.

App with Checkbox and Radio Buttons

Sliders

The next element we add is a slider. It is a quite helpful technique for a limited input range to understand the choice of specific value visually. The slider can be created with st.slider() method. The interesting thing, that the slider can be used not only for integers or float but for dates and times!

Select Boxes

Sometimes, we need to give the user many options to choose from (so radio buttons are not suitable). In these cases, the select box is an excellent choice. We can create a select box with the ability to choose only one option (with st.selectbox()method) or multiple of them (with st.multiselect() method).

Files

App with File Uploader

To submit inputs, you can use the button. To add a button, we will use st.button() method. As the button is not that smart by itself to submit the form after being pushed, we need to submit it using the if-else statement. For example, now, we will write to the user that the form is submitted if they pushed the button.

App with Button
App with sidebar
App with Columns

This is the end of my Streamlit tutorial. I hope you enjoyed it and now can create beautiful apps yourself! The full code for this article is below:

As you can see, our app took only 38 lines of code. Isn’t it magic? ☺️

Thank you for reading this article! There is actually a lot more to learn about Streamlit, so if you want more tutorials about it, say it in the comments! I hope you can give me some claps and ask a lot of questions!

Add a comment

Related posts:

Budgeting and planning is fun! Am I crazy???

Please tell me that you think budgeting and planning are fun too! This article is NOT going to be all about finance acronyms. When I went through Bynder’s budget process last year, there were a lot…

Used Car Data Set Modeling

Driving a car is important for people in general because it provides status and the opportunity for personal control and autonomy. In sparsely populated areas, owning a car is even more important…

Build native apps with GraalVM

GraalVM is a polyglot virtual machine that provides a shared runtime to execute applications written in multiple languages like Java, C, Python, and JavaScript. GraalVM also provides a Native Image…