Displaying Text in streamlit

🧠 Understanding the Streamlit Basic Functions

Understanding the Streamlit basic functions

👋 What is Streamlit?

If you’ve ever wanted to turn your Python scripts into web apps without learning HTML, CSS, or JavaScript, Streamlit is for you. It’s a simple, open-source framework that lets you create interactive dashboards, data apps, and ML demos—fast.

And the best part? You only need Python.

📌 Why Learn Streamlit Basics?

Streamlit helps you:

  • Build fast prototypes for machine learning models

  • Share data visualizations in a web browser

  • Add sliders, buttons, and inputs without much code

Let’s walk through the basic functions of Streamlit with a real code example.

🚀 Common Streamlit Functions You Should Know

Here are some Streamlit functions you’ll use a lot:

FunctionPurpose
st.title() Add a title to your app
st.header() Add a section header
st.subheader() Smaller headers for sections
st.write() Write text, dataframes, and more
st.button() Add a clickable button
st.slider() Add a slider for numeric input
st.text_input() Input text from the user
st.line_chart() Display a line chart

🧪 A Simple Example: Iris Dataset Explorer

We’ll use the classic Iris flower dataset from scikit-learn and build a basic app to explore it.

📁 Setup

First, make sure you install Streamlit:

pip install streamlit

💻 Code: Streamlit App to Explore Iris Dataset

# iris_app.py
import streamlit as st
from sklearn.datasets import load_iris
import pandas as pd
# Load Iris dataset
iris = load_iris()
df = pd.DataFrame(iris.data, columns=iris.feature_names)
# Title and intro
st.title("🌼 Iris Dataset Explorer")
st.write("Use the controls below to explore the classic Iris flower dataset.")
# Slider to select number of rows
num_rows = st.slider("How many rows to show?", min_value=5, max_value=150, value=10)
# Show table
st.write("Here are the first few rows of the dataset:")
st.dataframe(df.head(num_rows))
# Selectbox to choose a feature to plot
feature = st.selectbox("Pick a feature to plot", iris.feature_names)
# Plotting line chart
st.line_chart(df[feature])

▶️ To run the app:

streamlit run iris_app.py

📝 What’s Happening in the Code?

Let’s break it down:

  • st.title() creates a big title.

  • st.slider() lets you pick how many rows to show.

  • st.dataframe() displays a slice of the dataset.

  • st.selectbox() helps you choose a column.

  • st.line_chart() automatically makes a line chart.

No need for a backend, HTML, or frontend knowledge. Just Python.

🏁 Final Thoughts

Streamlit is perfect for Python users who want to build interactive tools. If you’re learning machine learning or data science, it’s worth exploring.

You now know:

  • Key Streamlit functions

  • How to build a small app

  • How to connect it with real data

References

Last modified: Thursday, 26 June 2025, 6:42 PM