Streamlit, an innovative open-source Python library, has revolutionized the way data scientists and machine learning engineers create and share interactive web apps. If you're new to Streamlit and eager to dive into some Python samples, you've come to the right place. This guide walks you through creating engaging web applications step by step.

Before we proceed, ensure you have Streamlit installed. If not, you can easily install it via pip: pip install streamlit. Once installed, you're ready to start building your first web app!

Getting Started with Streamlit
Let's begin with a simple "Hello, World!" application to familiarize yourself with Streamlit's basic syntax.

Create a new Python file (e.g., hello_world.py) and insert the following code:
```python import streamlit as st st.write("Hello, World!") ```
To run the app, use the following command in your terminal: streamlit run hello_world.py. You should see "Hello, World!" displayed in your browser.

Markdown Support
Streamlit supports Markdown, allowing you to format text effortlessly. Update your hello_world.py file as follows:
```python import streamlit as st st.markdown("# Hello, World! **:smile:**") ```

Reload the app, and you'll notice the text is now a header (H1) with an emoji. Formatting text in Streamlit has never been easier!
Adding Interactive Elements
Mighty Streamlit isn't just about displaying text; it excels in creating engaging, interactive content. Let's add an input widget to take user inputs:

```python import streamlit as st name = st.text_input("What is your name?") if st.button("Submit"): st.write(f"Hello, {name}!") ```
Refresh the app, and you'll find an input field where users can enter their names. Clicking "Submit" greets them with a personalized message.




















Building a Data Visualization App
Now that we've covered the basics, let's create a more complex web application that visualizes data using Streamlit's extensive suite of data visualization tools.
Create a new file called data_visualization.py and insert the following code:
```python import streamlit as st import pandas as pd import matplotlib.pyplot as plt # Load data (Assuming you have a CSV file named 'data.csv') data = pd.read_csv("data.csv") # Display data st.write(data) # Create a bar chart using Matplotlib fig, ax = plt.subplots() ax.bar(data['Category'], data['Value']) st.pyplot(fig) ```
Replace "data.csv" with the path to your actual CSV file. Run the app using streamlit run data_visualization.py. You'll see your data displayed and a bar chart rendered using Matplotlib, which Streamlit seamlessly integrates.
Creating a Data Form
Streamlit allows users to create responsive forms for data input. Let's add a form to our previous data visualization app:
```python # ... (Previous code remains the same) # Create a form with st.form("my_form"): category = st.text_input("Category") value = st.number_input("Value") submit = st.form_submit_button("Submit") # If form is submitted, add data to dataframe if submit: data.loc[len(data)] = [category, value] st.write(data) ```
With this form, users can input new categories and values, which are then added to the DataFrame andervaizlied.
And there you have it – a comprehensive guide to getting started with Streamlit Python samples. You've built interactive web applications, taken user input, visualized data, and handled form submissions. The possibilities with Streamlit are virtually endless, so keep experimenting and watch your data come to life!