StreamLit - Data Scientists tool for developing web apps

  • StreamLit is a tool for Data Scientists and Machine Learning Engineers to create the front end of the web application.
  • StreamLit is a wrapper around JavaScript, HTML, and CSS.
  • It helps developers with no expertise in JavaScript, HTML, and CSS create interactive web-based front ends for the models.

Also, Check out our Article on:

Pros and Cons of Streamlit

Pros:

  • Interactive
  • Customizable, and does not require any front end experience.​
  • Deployment is easy​
  • Active Community​

Cons:

  • The front-end interface is fixed, and developers cannot adjust the position of controls​.
  • Early stages of development​.

Getting Started with StreamLit

→ Downloading StreamLit

pip install streamlit

→ Running the app.py file

streamlit run app.py 

Setting up the web App

import streamlit as st
import pandas as pd
  • Title:
    Let’s start with the title of the web app, use your python script to write the codes.
st.title("First StreamLit App")
  • Header:
st.header("Abhigyan's App")
  • Subheader:
st.subheader("I am a Data Science Researcher at INSAID")
  • Text and markdown:
st.text("INSAID: India’s No.1 Online School to Learn Data Science & AI")
st.markdown("[INSAID](https://www.insaid.co/)")
st.write()
  1. You can pass in multiple arguments, all of which will be written.
  2. Its behaviour depends on the input types as follows.
  3. It returns None, so it’s “slot” in the App cannot be reused.
st.write(pd.DataFrame({'A': [1, 2, 3, 4],
'B': [5, 6, 7, 8]}))

Interactive widgets

  • Button:
st.button(label)
if st.button("Start"):
st.text("Hi! Welcome to the Web App")
  • Checkbox:
st.checkbox(label, value = False)
yes = st.checkbox("Move Forward")if yes:
st.text("Great Choice!")
  • Radio:
st.radio(label, options, index = 0)
options = ['Beginner', 'Intermediate', 'Master', 'GODLY']
genre = st.radio("How skilled are you at Data Science", options, index = 2)
if genre == 'Beginner':
st.text("Keep pushing yourself, if you want a boost check out:")
st.markdown("[INSAID](https://www.insaid.co/)")
elif genre == 'Intermediate':
st.text("Keep learning and you will succeed.")
st.markdown("[INSAID](https://www.insaid.co/)")
elif genre == 'Master':
st.write("Awesome! *Master Shifu* :sunglasses:")
elif genre == 'GODLY':
st.write("Welcome to my webpage")
else:
st.write("You didn't select anything")
  • Selectbox:
st.selectbox(label, options, index = 0)
exp = ["0-1", "2-5", "6-11", "> 12"]
option = st.selectbox("What is your experience level", exp)
st.write("You have a experience of:", option)
  • Multiselect:
st.multiselect(label, options, default = None)
mem = ['Father', 'Mother', 'Son', 'Daughter', 'Grand Mother',
'Grand Father']
option = st.multiselect("How many members in your family", mem,
['Father, 'Mother'])
st.write('You selected:')
for i in option:
st.write(i)
  • Slider:
st.slider(label, min_value, max_value, value, step, format)
age = st.slider("How old are you?", 6, 100, 1)
st.write("I am", age, "years old")
st.text_input(label, value, max_chars, type)
comp = st.text_input("Your Company name")
st.write("your comany name is", comp)
  • Text Area:
st.text_area(label, value, height, max_chars)
text = st.text_area("Write about Yourself")
st.write('About you:', text)

Displaying Charts

  • Line Chart:
st.line_chart(data, width, height, use_container_width)
chart_data = pd.DataFrame(np.random.randn(20, 3),
columns=['a', 'b', 'c'])
st.line_chart(chart_data)
  • Area chart:
st.area_chart(data, width, height, use_container_width)
chart_data = pd.DataFrame(np.random.randn(20, 3),
columns=['a', 'b', 'c'])
st.area_chart(chart_data)
  • Similarly you can plot bar chart by using the function st.bar_chart().
  • Pyplot:
st.pyplot(fig, clear_figure)
import matplotlib.pyplot as plt
import numpy as np

arr = np.random.normal(1, 1, size=100)
fig, ax = plt.subplots()
ax.hist(arr, bins=20)
st.pyplot(fig)

Display Media

  • Image:
st.image(image, caption, width, use_column_width, clamp, channels, output_format)
st.image(image, caption, use_column_width = True)

Sharing web apps

  1. Push your app in your GitHub repository, with the requirements.txt will all the packages that need to be installed for a smooth flow of the web app.
  2. Create an account in share.streamlit.io
  3. Paste your GitHub repo’s URL after clicking on ‘Deploy an app’.

Also, Check out our Article on:

Visit us on https://www.insaid.co/

--

--

--

One of India’s leading institutions providing world-class Data Science & AI programs for working professionals with a mission to groom Data leaders of tomorrow!

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Visualizing the Data

4 Best practices for designing data visualizations

Which measures are more effective in controlling COVID-19?

Automatic Market Share Analysis Using Web Scrapping, Text Processing, and Visualization

5 Mistakes I Wish I Had Avoided in My Data Science Career

Filling the gap in data science education with project-based learning

For more scalable AI, should we teach data scientists to think more like developers? (Part 2)

«Weekly Report» The Change of AIDUS QTS Profit Rate (August 7, 2020)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
INSAID

INSAID

One of India’s leading institutions providing world-class Data Science & AI programs for working professionals with a mission to groom Data leaders of tomorrow!

More from Medium

Sentiment Analysis of Reddit Comments on Russia-Ukraine War with Python

What is Streamlit?

Formula 1 Final Round Twitter Analysis: Scraping

How to make text in images on the harddrive searchable

output of the script