Hey there đ,
Before moving on to the content , take a quick look. đ
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!
Make sure that you have Python 3.6 or greater installed.
Install Streamlit using PIP and run the âhello worldâ app:
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
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.
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.
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
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.
chart_data = pd.DataFrame(
np.random.randn(20, 3),
columns=['a', 'b', 'c'])
st.line_chart(chart_data)
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.
map_data = pd.DataFrame(
np.random.randn(1000, 2) / [50, 50] + [37.76, -122.4],
columns=['lat', 'lon'])
st.map(map_data)
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
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)
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
Read more about how to share - Official workflow
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!!!
So in retrospect, in 2015, not a single person got the answer right to "Where do you see yourself 5 years from now?"
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 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 ! đđ
Top comments (0)