VOOZH about

URL: https://www.geeksforgeeks.org/python/a-beginners-guide-to-streamlit/

⇱ A Beginners Guide To Streamlit - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

A Beginners Guide To Streamlit

Last Updated : 16 Jul, 2025

Streamlit is an open-source Python library for building interactive web apps using only Python. It's ideal for creating dashboards, data-driven web apps, reporting tools and interactive user interfaces without needing HTML, CSS or JavaScript.

This article introduces key Streamlit features, shows how to build a simple app and explains how to run it on a local server using minimal code.

Streamlit Installation

Make sure Python and pip are already installed on your system. To install Streamlit, run the following command in the command prompt or terminal:

pip install streamlit

How to run Streamlit file?

To run a Streamlit app, open the command prompt or Anaconda prompt and type:

streamlit run filename.py

For example, if file name is sample.py, run:

streamlit run sample.py

After running the command, Streamlit starts a local development server and displays a URL (http://localhost:8501). Open this URL in your browser to view and interact with the app.

πŸ‘ cmd_runstreamlit
Run Streamlit file

Understanding Streamlit basic functions

Streamlit offers simple built-in functions to create interactive web apps using Python. These functions help display text, add widgets, visualize data and handle user input.

Let’s explore them one by one.

1. Title

This basic Streamlit example displays a title on the web page, confirming that Streamlit is set up and running correctly.

Output

πŸ‘ Output_title
Output of Title

2. Header and Subheader

This example demonstrates how to add a header and subheader in a Streamlit app.

Output

πŸ‘ Output_headerSubheader
Output of Header/Subheader

3. Text

It shows how to display plain text in a Streamlit app using st.text() function.

Output

πŸ‘ Output_text
Output of Text

4. Markdown

This example uses st.markdown() to show formatted text. The ### creates a level 3 header, used for medium-sized headings in the app.

Output

πŸ‘ Output_markdown
Output of Markdown

5. Success, Info, Warning, Error and Exception

This example shows how to display different types of messages and alerts in a Streamlit app using built-in functions like st.success(), st.info(), st.warning(), st.error() and st.exception(). These functions help communicate status, information, warnings, errors and exceptions to users clearly.

Output

πŸ‘ Output_diffWarnings
Output of Success, Information, Warning, Error and Exception

6. Write

This example uses st.write() that can display text, numbers, data structures and even charts. Here, it's used to show plain text and the output of Python’s built-in range() function.

Output

πŸ‘ Output_write
Output of write

7. Display Images

This example demonstrates how to display an image using Pillow library. The image is opened with Image.open() and displayed with st.image(), where the width parameter controls its size.

Output

πŸ‘ Output_displayimages
Output of Display Images

8. Checkbox

This example uses a checkbox in Streamlit to toggle content visibility. When the checkbox labeled "Show/Hide" is checked, it displays a text message on the screen.

Output

πŸ‘ Output_checkbox1
Checkbox is not checked
πŸ‘ Output_checkbox2
The text is displayed when the box is checked

9. Radio Button

This example demonstrates how to use radio buttons to let users select one option from a list. Based on the selected gender, the app displays the result using st.success()

Output

πŸ‘ Output_radiobutton1
Success shows Male when Male option is selected
πŸ‘ Output_radiobutton2
Success shows Female when Female option is selected

10. Selection Box

This example uses a select box in Streamlit to let users choose one option from a dropdown list. The selected item is then displayed on the screen.

Output

πŸ‘ Output_selectionbox1
Selectbox showing options to select from
πŸ‘ Output_selectionbox2
Selcted option is printed

11. Multi-Selectbox

This example demonstrates how to use a multiselect box in Streamlit, allowing users to choose multiple options from a list. The app then displays the number of selected items.

Output

πŸ‘ Output_multiselect1
Multi - Selectbox
πŸ‘ Output_multiselect2
Selected 2 options

12. Button

This example shows how to use buttons in Streamlit. Buttons can trigger specific actions when clicked, such as displaying a message or running a function.

Output

πŸ‘ Output_button1
Click the first button
πŸ‘ Output_button2
Click the About button

13. Text Input

Text input fields allow users to enter custom data. This example collects a user's name, formats it with proper capitalization and displays it when Submit button is clicked, simulating a basic form interaction.

Output

πŸ‘ Output_textInput1
Text Input
πŸ‘ Output_textInput2
Display success message when the submit button is clicked

14.  Slider

Sliders provide a way to select numeric values within a range. This example lets users choose a level between 1 and 5 and displays the selected value instantly. It is useful for settings like ratings, difficulty levels or thresholds.

Output

πŸ‘ Output_slider
Output of slider

Mini Project

Let’s put everything we've learned so far into practice by building a BMI Calculator web app using Streamlit. The formula to calculate Body Mass Index (BMI) when weight is in kilograms and height is in meters is:

bmi = weight/height2

Output

πŸ‘ BMIcalculator1
BMI calculator web app

After entering all the required fields:

πŸ‘ BMICalculator2
BMI Calculator
Comment