0% found this document useful (0 votes)
72 views4 pages

Python BAKMR010399002

Uploaded by

Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views4 pages

Python BAKMR010399002

Uploaded by

Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Alright!

Let's delve into the fascinating world of Streamlit, a powerful tool for creating interactive web applications with
Python.

### Introduction to Streamlit

Streamlit is an open-source Python library that makes it easy to create and share beautiful, custom web apps for
machine learning and data science. It's designed to turn data scripts into shareable web apps in a matter of minutes,
making it a favorite among data scientists who want to showcase their findings without needing to delve into web
development.

#### Key Features:

1. **Simplicity**: Streamlit's API is straightforward, allowing you to create complex applications with minimal code.

2. **Interactive Widgets**: Add widgets like sliders, buttons, and text inputs effortlessly.

3. **Data Visualization**: Integrate with popular visualization libraries like Matplotlib, Altair, and Plotly.

4. **Real-time Updates**: Automatically re-runs your code every time you save your source file, ensuring your app is
always up to date.

### Getting Started with Streamlit

To get started with Streamlit, you first need to install it. You can do this using pip:

```bash

pip install streamlit

```

Once installed, you can create your first Streamlit app with a simple Python script. Let's create a basic "Hello, World!"
application.

#### Hello, World! Application

```python

import streamlit as st

st.title("Hello, World!")
st.write("Welcome to your first Streamlit app.")

```

To run your app, save the script (e.g., `app.py`) and use the following command in your terminal:

```bash

streamlit run app.py

```

Your browser will open, displaying your new web application.

### Adding Interactivity

One of the most powerful aspects of Streamlit is its ability to create interactive applications. Let's add a few widgets to
our app.

#### Example: User Input and Display

```python

import streamlit as st

st.title("Interactive Streamlit App")

name = st.text_input("Enter your name:")

if name:

st.write(f"Hello, {name}!")

number = st.slider("Pick a number", 0, 100)

st.write(f"Your number is {number}")

```
In this example, we add a text input widget and a slider. When the user inputs their name or picks a number, the app
dynamically updates to show their inputs.

### Displaying Data

Streamlit makes it easy to display data in various forms. Let's look at how to display a DataFrame and a chart.

#### Example: DataFrame and Chart

```python

import streamlit as st

import pandas as pd

import numpy as np

st.title("Data Display in Streamlit")

# Create a DataFrame

data = pd.DataFrame({

'A': np.random.rand(10),

'B': np.random.rand(10)

})

st.write("Here is a sample DataFrame:")

st.dataframe(data)

# Create a chart

st.line_chart(data)

```

In this example, we create a DataFrame with random data and display it using `st.dataframe()`. We also create a line
chart to visualize the data.
### Deployment

Once you've built your Streamlit app, you can deploy it using various cloud platforms like Streamlit Sharing, Heroku, or
AWS. Streamlit Sharing is the most straightforward option, specifically designed for Streamlit apps.

#### Deploying on Streamlit Sharing

1. **Sign up** for a Streamlit Sharing account.

2. **Push your app** to a public GitHub repository.

3. **Deploy** your app directly from GitHub through Streamlit Sharing's interface.

### Conclusion

Streamlit is a powerful, user-friendly tool that democratizes the creation of web apps for data science. With minimal
effort, you can build interactive applications that not only display your data but also allow users to interact with it in
meaningful ways. Whether you're showcasing a machine learning model, creating data visualizations, or building an
interactive dashboard, Streamlit makes the process efficient and enjoyable.

Hope this content helps you get started with Streamlit! If you have any specific requirements or questions, feel free to
ask.

You might also like