How to use Streamlit :The fastest way to build and share data apps.
Tags: python, productivity, beginners, tutorial
Published: 2020-12-31 13:35:18

---
title: How to use Streamlit :The fastest way to build and share data apps.
published: true
description: streamlit docs
tags: python, productivity, beginners , tutorial
series: Python Journey
cover_image: https://i.ibb.co/S69tSQk/Streamlit.png

---

Hey there 🖐,
Before moving on to the content , take a quick look. 👀

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/80rhg92j1mvofqscfupe.gif)

# Table of contents

* 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. 🤩

* In just a few minutes you can build and deploy powerful data apps 🚀🚀 - so let’s get started!

1. Make sure that you have Python 3.6 or greater installed.

2. Install Streamlit using PIP and run the ‘hello world’ app:

```cmd
pip install streamlit
streamlit hello
```

## Create your first Streamlit app
First, we’ll create a new Python script and import Streamlit.

Create a new Python file named app.py, then open it with your IDE or text editor.

Next, import Streamlit

```python
import streamlit as st
# To make things easier later, we're also importing numpy and pandas for
# working with sample data.
import numpy as np
import pandas as pd
```
Run your app. A new tab will open in your default browser. It’ll be blank for now. That’s OK.

```cmd
streamlit run app.py
```

Write a data frame
Along with magic commands, st.write() is Streamlit’s “Swiss Army knife”. You can pass almost anything to st.write(): text, data, Matplotlib figures, Altair charts, and more. Don’t worry, Streamlit will figure it out and render things the right way.



```python
st.title('My first app')
st.write("Here's our first attempt at using data to create a table:")
st.write(pd.DataFrame({
    'first column': [1, 2, 3, 4],
    'second column': [10, 20, 30, 40]
}))
```

output will be like

![theme](https://i.ibb.co/JkvqJ3s/first.png)

## Draw charts and maps

Streamlit supports several popular data charting libraries like Matplotlib, Altair, deck.gl, and more. In this section, you’ll add a bar chart, line chart, and a map to your app.

Draw a line chart
You can easily add a line chart to your app with st.line_chart(). We’ll generate a random sample using Numpy and then chart it.

```python
chart_data = pd.DataFrame(
     np.random.randn(20, 3),
     columns=['a', 'b', 'c'])
st.line_chart(chart_data)
```
![theme](https://i.ibb.co/jw1zg8d/line-chart.png)


## Plot a map
With st.map() you can display data points on a map. Let’s use Numpy to generate some sample data and plot it on a map of San Francisco.

```python
map_data = pd.DataFrame(
    np.random.randn(1000, 2) / [50, 50] + [37.76, -122.4],
    columns=['lat', 'lon'])

st.map(map_data)
```
![theme](https://i.ibb.co/TMznYww/scatter-chart.png)

## Show progress

* When adding long running computations to an app, you can use st.progress() to display status in real time.

First, let’s import time. We’re going to use the time.sleep() method to simulate a long running computation:

``` import time ```
Then add the code

``` python
left_, right_ = st.beta_columns(2)
latest_iteration = st.empty()
bar = st.progress(0)
pre = left_.button('Start counter')
if pre:
  bar.progress(0)
  for i in range(100):
    # Update the progress bar with each iteration.
    latest_iteration.text(f'Iteration {i+1}')
    bar.progress(i + 1)
    time.sleep(0.1)

```

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/19dya5ppbdfmh4f2sv8g.gif)

## Share your app

* After you’ve built a Streamlit app, it’s time to share it! To show it off to the world you can use Streamlit sharing to deploy, manage, and share your app for free. 

* Streamlit sharing is currently invitation only so  request an invite .

It works in 3 simple steps: 🥳

* Put your app in a public Github repo (and make sure it has a requirements.txt!)

* Sign into share.streamlit.io

* Click ‘Deploy an app’ and then paste in your GitHub URL

That’s it! 🎈You now have a publicly deployed app that you can share with the world. 💪

Read more about how to make apps - [Official docs](https://docs.streamlit.io/en/stable/getting_started.html)

Read more about how to share - [Official workflow](https://www.streamlit.io/sharing)


Thats it for now. 

This was my very last post on the year 2020. What an interesting and weired year it has been in all the worst ways lads!!! 

<blockquote>So in retrospect, in 2015, not a single person got the answer right to "Where do you see yourself 5 years from now?"</blockquote>

![sad](https://media.giphy.com/media/W0c3xcZ3F1d0EYYb0f/giphy.gif)

On the bright side, I  got to write more contents on this year than any other year.

It is finaly over. I wanted to say thank to each one of you.

![thanks](https://media.giphy.com/media/L0rChNMtyQBCmQRvi6/giphy.gif)

Thanks for reading my contents. If you learned something new from my posts please let me know. 

Dont hesitate to share if there any mistakes that i need to correct or topics that i have to research more.

See you next year

Hasta Pronto ! :raised_hands::raised_hands:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/jso4343dxloqe2ll29k3.gif)