Madhurima Mindscape

Modules, Materials, Moments, Memories, and More

🏡 Home 📑 Saved 📂 Blogs

Building Interactive Apps with Streamlit

November 17, 2026

Calculating reading time...

Building a web application usually involves working with both frontend and backend technologies. We need to design the user interface, handle user interactions, process inputs, and display the results. But what if we could build an interactive web application using Python alone?

This is where Streamlit comes in. Streamlit is an open-source Python framework that makes it easier to create interactive web applications without having to write traditional frontend code using HTML, CSS, or JavaScript.

It is particularly useful for Python projects involving Machine Learning, Data Science, data visualization, dashboards, and other applications where we want to present Python functionality through a simple user interface.

Streamlit interactive application demonstration

Streamlit – Building interactive applications using Python. (Explore Streamlit)

In this tutorial, I'll walk through the basic features of Streamlit using a simple Python application. We'll explore how to display text, headings, messages, images, buttons, checkboxes, radio buttons, selection boxes, text inputs, and sliders.

We'll also see how to run a Streamlit application locally and how changes in the Python file are reflected in the running application.

"Sometimes, the easiest way to build an interactive application is to use the language you already know."

🐍 1. What is Streamlit?

Streamlit is a Python framework that allows developers to turn Python scripts into interactive web applications. It provides predefined functions for creating different frontend components.

Instead of manually creating web pages and handling frontend interactions, we can use Streamlit functions directly in our Python code.

For example, we can use:

  • st.title(): Display the main title of an application.
  • st.header(): Display a section heading.
  • st.text(): Display plain text.
  • st.button(): Create an interactive button.
  • st.text_input(): Accept text from users.
  • st.slider(): Allow users to select a numerical value.

Streamlit is especially useful when working with Machine Learning models because we can create a user interface for a model without building a separate frontend.

For example, we can train a prediction model, take input from a user through Streamlit widgets, pass that input to the model, and display the prediction on the same application.

💡 My tip: If you already know Python and want to build simple interactive applications, Streamlit is a great framework to explore.

💻 2. Setting Up the Development Environment

Before creating our first Streamlit application, we need Python and a code editor.

Visual Studio Code

I use Visual Studio Code to write and execute Python programs. You can download it from its official website:

Download Visual Studio Code

Follow these steps to prepare your environment:

  • Download Visual Studio Code according to your operating system.
  • Install Python if it is not already installed.
  • Open Visual Studio Code.
  • Create a new Python file with the .py extension.
  • Open the integrated terminal to execute Python commands.

Installing Streamlit

Streamlit can be installed using Python's package installer, pip.

pip install streamlit

If you are working inside a virtual environment, activate it before installing the package.

Once the installation is complete, we are ready to create our first Streamlit application.

💡 My tip: Keep your project dependencies organized. For larger projects, using a virtual environment helps avoid conflicts between packages.

🚀 3. Running Your First Streamlit Application

Unlike a regular Python script, a Streamlit application is executed using the Streamlit command.

Create a Python file named app.py and add the following code:

import streamlit as st

st.title("My First Streamlit Application")

st.header("Welcome!")

st.text("Hello Everyone!")

Save the file and open the terminal in the project directory.

Execute the following command:

streamlit run app.py

Here, app.py is the name of the Python file containing our Streamlit code.

After executing the command, Streamlit starts a local development server and provides a URL to access the application.

By default, the application runs at:

http://localhost:8501

Open this URL in your browser to view the application.

If the default port is already occupied, Streamlit can use another available port.

Updating the Application

One useful feature of Streamlit is its development workflow. When you modify and save the Python file, Streamlit can automatically rerun the application.

This makes it convenient to experiment with different components and see the changes in the browser.

💡 My tip: Keep the terminal running while developing your application. You can edit your Python code and check the updated output in the browser.

📝 4. Displaying Titles, Headers and Text

Streamlit provides several functions to display different types of text content.

Title

The st.title() function displays the main title of the application.

st.title("Basic App in Python Using Streamlit!!")

Header and Subheader

We can use headers to organize different sections of the application.

st.header("This is a Header")

st.subheader("This is a Subheader")

Plain Text

The st.text() function displays simple text in the application.

st.text("Hello Everyone!!!")

Markdown

Streamlit also supports Markdown formatting through the st.markdown() function. This allows us to display formatted text and headings.

st.markdown("# This is a Markdown Header 1")

st.markdown("## This is a Markdown Header 2")

st.markdown("### This is a Markdown Header 3")

Markdown headings can be created using one to six hash symbols, with each level representing a different heading size.

These functions are useful when organizing content and making an application easier to understand.

📢 5. Displaying Success, Information and Error Messages

Streamlit includes predefined functions for displaying different types of status messages.

These messages are useful for communicating the result of an operation or informing users about something happening in the application.

Success Message

The st.success() function displays a success message.

st.success("For Showing Successful Submission")

Information Message

The st.info() function displays an informational message.

st.info("Information")

Warning Message

The st.warning() function displays a warning message.

st.warning("This is a Warning")

Error Message

The st.error() function displays an error message.

st.error("Error Encountered!!")

Displaying Exceptions

We can also display exception information using st.exception().

exp = ZeroDivisionError("Trying to divide by Zero")

st.exception(exp)

These functions make it easier to display the status of different operations without creating custom message components.

🔢 6. Displaying Python Objects with st.write()

The st.write() function is a flexible way to display different types of content in a Streamlit application.

For example, we can display a message or even a Python object.

st.write("Writing Python Inbuilt Range Function")

st.write(range(10))

The function can also display many other Python objects, including strings, numbers, lists, dictionaries, and data structures.

This makes it particularly useful when displaying intermediate results or exploring data while developing an application.

🖼️ 7. Displaying Images Using Pillow

We can display images in Streamlit using the st.image() function.

In this example, I used Pillow, a Python imaging library, to open an image file.

First, install Pillow:

pip install Pillow

Import the Image module and load the image:

from PIL import Image

# Loading an image
img = Image.open("Picture-1.jpg")

# Displaying the image
st.image(img, width=200)

Here:

  • Image.open(): Opens the image file.
  • img: Stores the loaded image.
  • st.image(): Displays the image in the application.
  • width=200: Sets the display width of the image.

Make sure that the image file is available at the specified path relative to your application.

💡 My tip: Keep images and other supporting files organized inside your project directory so that they can be accessed easily.

☑️ 8. Creating a Checkbox

A checkbox allows users to select or deselect an option. In Streamlit, we can create one using st.checkbox().

A checkbox returns a Boolean value: True when selected and False when not selected.

if st.checkbox("Show/Hide"):

    st.text("Showing the widget")

In this example, the text is displayed only when the checkbox is selected.

This is useful when we want to show or hide additional information based on user interaction.

🔘 9. Creating Radio Buttons

Radio buttons allow users to select one option from a predefined set of choices.

We can create radio buttons using st.radio().

status = st.radio(
    "Select Gender: ",
    ("Male", "Female")
)

if status == "Male":
    st.success("Male")
else:
    st.success("Female")

The first argument represents the label of the radio button, while the second argument contains the available options.

The selected option is stored in the status variable.

We can then use conditional statements to perform different actions depending on the selected value.

📋 10. Creating Selection Boxes

Streamlit provides selection widgets that allow users to choose one or multiple options.

Select Box

The st.selectbox() function allows users to select a single option from a list.

hobby = st.selectbox(
    "Hobbies: ",
    ["Dancing", "Reading", "Sports"]
)

st.write("Your hobby is: ", hobby)

The selected hobby is stored in the hobby variable and displayed using st.write().

Multiselect Box

If we want users to select multiple options, we can use st.multiselect().

prog_lang = st.multiselect(
    "Programming Languages: ",
    ["C", "C++", "PHP", "Python", "R", "Ruby"]
)

st.write(
    "Programming Languages you selected are: ",
    len(prog_lang),
    prog_lang
)

Unlike a regular select box, the multiselect widget returns the selected options as a list.

We can use len(prog_lang) to find the number of selected languages and display the selected values directly.

💡 What I learned: Use selectbox when only one choice is required and multiselect when users should be able to choose several options.

🖱️ 11. Creating Interactive Buttons

Buttons are among the most commonly used components in interactive applications.

Streamlit provides the st.button() function to create buttons.

Simple Button

We can create a basic button using:

st.button("Click me for no reason")

We can also use the return value of a button to execute a block of code when it is clicked.

Button with an Action

if st.button("About"):

    st.text("Welcome To My App!!!")

In this example, the welcome message is displayed when the user clicks the About button.

This is useful for actions such as displaying additional information, submitting operations, or triggering application functionality.

⌨️ 12. Taking User Input with Text Input

Interactive applications often need to collect information from users. For this, Streamlit provides the st.text_input() function.

Let's create a simple input field that accepts a user's name.

name = st.text_input(
    "Enter Your name",
    "Type Here ..."
)

if st.button("Submit"):

    result = name.title()

    st.success(result)

Here:

  • st.text_input(): Creates a text input field.
  • name: Stores the entered text.
  • st.button(): Creates a Submit button.
  • name.title(): Converts the entered text into title case.
  • st.success(): Displays the processed result.

For example, if a user enters "madhurima rawat", the application displays "Madhurima Rawat" after clicking Submit.

This is a simple example of collecting and processing user input in a Streamlit application.

🎚️ 13. Creating Sliders

Sliders allow users to select a value from a specified range.

We can create a slider using the st.slider() function.

level = st.slider(
    "Select The Level",
    1,
    5
)

st.text("Selected: {}".format(level))

The first argument represents the slider label, while the second and third arguments specify the minimum and maximum values.

The selected value is stored in the level variable and displayed using st.text().

Sliders are useful for selecting numerical values such as ratings, thresholds, ranges, and model parameters.

🧩 14. Putting Everything Together

Now that we have explored the basic Streamlit components, let's combine them into one application.

The following example brings together the widgets covered in this tutorial.

import streamlit as st
from PIL import Image

# Application title
st.title("Basic App in Python Using Streamlit!!")

# Headers and text
st.header("This is a Header")
st.subheader("This is a Subheader")
st.text("Hello Everyone!!!")

# Markdown
st.markdown("# This is a Markdown Header 1")
st.markdown("## This is a Markdown Header 2")

# Status messages
st.success("Successful Submission")
st.info("Information")
st.warning("This is a Warning")
st.error("Error Encountered!!")

# Display Python objects
st.write("Writing Python Inbuilt Range Function")
st.write(range(10))

# Display an image
img = Image.open("Picture-1.jpg")
st.image(img, width=200)

# Checkbox
if st.checkbox("Show/Hide"):
    st.text("Showing the widget")

# Radio button
status = st.radio(
    "Select Gender: ",
    ("Male", "Female")
)

st.success(status)

# Select box
hobby = st.selectbox(
    "Hobbies: ",
    ["Dancing", "Reading", "Sports"]
)

st.write("Your hobby is:", hobby)

# Multiselect
prog_lang = st.multiselect(
    "Programming Languages: ",
    ["C", "C++", "PHP", "Python", "R", "Ruby"]
)

st.write(
    "Programming Languages selected:",
    len(prog_lang),
    prog_lang
)

# Buttons
st.button("Click me for no reason")

if st.button("About"):
    st.text("Welcome To My App!!!")

# Text input
name = st.text_input(
    "Enter Your name",
    "Type Here ..."
)

if st.button("Submit"):
    st.success(name.title())

# Slider
level = st.slider("Select The Level", 1, 5)

st.text("Selected: {}".format(level))

Save the code in a file named app.py and execute it using:

streamlit run app.py

Make sure Pillow is installed and Picture-1.jpg is available in the correct location before running the application.

You can now explore the different components, interact with the widgets, and modify the code to customize your application.

💡 My tip: Start with simple components and gradually combine them to build more useful applications.

🤖 15. Using Streamlit for Machine Learning Projects

One of the most interesting uses of Streamlit is deploying Machine Learning projects through an interactive web interface.

A typical Machine Learning project involves training a model, accepting input features, processing those inputs, and generating predictions.

Streamlit can provide the interface for this entire interaction.

For example, a simple prediction application can follow this workflow:

  • Train a Machine Learning model using Python.
  • Load the trained model into the Streamlit application.
  • Use widgets to collect input from users.
  • Pass the input values to the prediction model.
  • Display the prediction using Streamlit components.

This approach can be used for regression, classification, data analysis, and many other Python-based projects.

In my Streamlit-Programs repository, I have also explored applications involving Linear Regression, Naive Bayes classification, and built-in datasets from scikit-learn.

These examples demonstrate how the same Streamlit workflow can be used for different Python and Machine Learning applications.

💜 Building Python Applications Without the Frontend Complexity

Streamlit makes it easier to turn Python scripts into interactive applications. Its predefined components help us display content, collect user input, create widgets, and present results without building a traditional frontend from scratch.

Through this tutorial, we explored how to set up Streamlit, run a local application, display different types of content, work with images, and create interactive components such as checkboxes, radio buttons, selection boxes, buttons, text inputs, and sliders.

These basic components provide a foundation for building more advanced applications, especially when working with Python, Machine Learning, and Data Science projects.

If you are new to Streamlit, I would recommend starting with small applications and experimenting with the available widgets before moving on to larger projects.

"You don't always need a separate frontend to make your Python projects interactive."

Want to explore the complete code? Visit my GitHub repository to check out the Streamlit programs and examples.

Explore Streamlit Programs