streamlit hello
To showcase your project
Installation streamlit by using the command:
pip install streamlit
To check whether everything is ready
Now lets create our first app
Create a python file with the following script (Here we create a slider and out put of the slider. We develop an app get result square of a number)
import streamlit as st
x = st.slider('x')
st.write(x, 'squared is', x * x)
Some of important Streamlit Widget sare
1. Slider
streamlit.slider(label, min_value=None, max_value=None, value=None, step=None, format=None)
2. Text Input
import streamlit as st
url = st.text_input('Enter URL')
st.write('The Entered URL is', url)
This is how the app looks:
3. Checkbox
import streamlit as st
import pandas as pd
import numpy as np
df = pd.read_csv("football_data.csv")
if st.checkbox('Show dataframe'):
st.write(df)
4. Select box
import streamlit as st
import pandas as pd
import numpy as np
df = pd.read_csv("football_data.csv")
option = st.selectbox(
'Which Club do you like best?',
df['Club'].unique())
'You selected: ', option
5. Multi Select
import streamlit as st
import pandas as pd
import numpy as np
df = pd.read_csv("football_data.csv")
options = st.multiselect(
'What are your favorite clubs?', df['Club'].unique())
st.write('You selected:', options)
To see more styles of API see: https://streamlit.io/docs/api.html
More practical example
import streamlit as st
x = st.slider('x')
st.write(x, 'squared is', x * x)
import streamlit as st
import pandas as pd
import numpy as np
st.title('Uber pickups in NYC')
DATE_COLUMN = 'date/time'
DATA_URL = ('https://s3-us-west-2.amazonaws.com/'
'streamlit-demo-data/uber-raw-data-sep14.csv.gz')
@st.cache
def load_data(nrows):
data = pd.read_csv(DATA_URL, nrows=nrows)
lowercase = lambda x: str(x).lower()
data.rename(lowercase, axis='columns', inplace=True)
data[DATE_COLUMN] = pd.to_datetime(data[DATE_COLUMN])
return data
data_load_state = st.text('Loading data...')
data = load_data(10000)
data_load_state.text('Loading data... done!')
if st.checkbox('Show raw data'):
st.subheader('Raw data')
st.write(data)
st.subheader('Number of pickups by hour')
hist_values = np.histogram(data[DATE_COLUMN].dt.hour, bins=24, range=(0,24))[0]
st.bar_chart(hist_values)
# Some number in the range 0-23
hour_to_filter = st.slider('hour', 0, 23, 17)
filtered_data = data[data[DATE_COLUMN].dt.hour == hour_to_filter]
st.subheader('Map of all pickups at %s:00' % hour_to_filter)
st.map(filtered_data)