Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ance-service into nickdelgrosso/issue18
  • Loading branch information
nickdelgrosso committed Jul 25, 2023
2 parents be3d7fe + 6c751c4 commit 0a3c6f7
Show file tree
Hide file tree
Showing 6 changed files with 421 additions and 0 deletions.
64 changes: 64 additions & 0 deletions learning_projects/webapp/Home.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import streamlit as st
import pandas as pd
import numpy as np
import seaborn as sns

st.title(':red[Home Page]')

st.header(":violet[Text elements]")

st.markdown(body='**:orange[Markdown support] with st.markdown**',help='this is a tooltip. :green[Look!] you can use _italics_ and **bold** here as well!')
st.markdown(body='Here is latex formula $a+b^2=c$')

st.markdown(body='**:orange[Code] with st.code**')
st.code(body='print("Hello World")',language='python')

st.divider()

code = '''
a = 20
b = 25
c = a + b
'''
st.code(body=code, language='python',line_numbers=True)

code = '''def get_name(name):
return name'''
st.code(body=code,language='python')

st.code(body='c=complex(a,b) #this is in matlab',language='matlab')
st.code(body='ls *.csv',language='bash')

st.write("---")

st.markdown(body='**:orange[Text] with st.text**')
st.text(body='This is a text with tooltip', help='here you go')
st.text(body='**bold** :green[color] **:green[bold color]** _:green[italicized color]_ **_:green[bold italicized color]_**',help='Notice text styling does not work')

"---"

st.markdown(body='**:orange[Text] with st.text**')

st.markdown(body='**:orange[Emoji support]** :sunglasses::+1::100:')

st.write('iBOTS team')
st.write(pd.DataFrame({'names':['Nicholas Del Grosso','Mohammad Bashiri','Sangeetha Nandakumar']}))

# magic command
df = pd.DataFrame({'names':['Nicholas Del Grosso','Mohammad Bashiri','Sangeetha Nandakumar']})
df

"---"

st.header(":violet[Data elements]")
st.markdown(body='**:orange[Dataframe] with st.dataframe**')

st.dataframe(data=df, width=None, height=None, use_container_width=False, hide_index=True, column_order=None, column_config=None)

st.markdown(body='**:orange[Data Editor] with st.data_editor**', help='Edit your data with this')
st.data_editor(data=df)


st.data_editor(data=df,column_config={
"names":st.column_config.Column("iBOTS")
})
Empty file.
192 changes: 192 additions & 0 deletions learning_projects/webapp/pages/1_Analysis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
import streamlit as st
from sklearn.datasets import load_iris
import pandas as pd
import numpy as np
import seaborn as sns
import time
import matplotlib.pylab as plt

def prep_page():
with st.sidebar:
with st.spinner('Loading'):
for i in range(10000):
pass

@st.cache_data
def load_dataset():
i = 0
my_bar = st.progress(0, text='')
with st.sidebar:
for i in range(100):
df = sns.load_dataset('titanic')
my_bar.progress(i + 1, text='#%d'%(i+1))
st.warning(f'You loaded same dataset for {i+1} times')
st.info('Done loading titanic dataset')
return df

def call_titanic():
st.title(':blue[Titanic database Analysis]')
st.markdown(body='Loading titanic dataset 100 times')
df = load_dataset()
# st.balloons()

with st.expander('Display data'):
st.write(df)

st.success('Successfully setup the analysis project')
"---"

st.markdown('Removing null values')
len_original = len(df)
df = df.dropna()
delta = len(df) - len_original
st.metric("Number of rows",value=len(df),delta=delta)

'''---'''
edit_true = st.checkbox(label='Do you want to edit data?')

if edit_true:
col_config = {
"sex":st.column_config.SelectboxColumn(label='Sex',options=['female','male']),
"age":st.column_config.NumberColumn(label='Age',min_value=0.,max_value=120),
"pclass":st.column_config.SelectboxColumn(label='Passenger class',options=[1,2,3]),
"alone":st.column_config.CheckboxColumn(label='Survived')
}


df_edited = st.data_editor(
df,
column_config=col_config,
use_container_width=True,
hide_index=True,
num_rows="fixed",
)

else:
df_edited = df

'''---'''

option = st.radio(label='Analysis options',options=['Sex','Survived','Class','Age','Clear'])

if option == 'Sex':
n_male = len(df[df.sex == 'male'])
n_female = len(df[df.sex == 'female'])
col1,col2=st.columns(2)
col1.metric('Number of male passengers',value=n_male)
col2.metric('Number of female passengers',value=n_female)
elif option == 'Survived':
survived = df[df.survived == 1]
n_survived = len(survived)
n_male_survived =len(survived[survived.sex == 'male'])
n_female_survived =len(survived[survived.sex == 'female'])
col1,col2,col3 = st.columns(3)
col1.metric("Survived",value=n_survived)
col2.metric("Number of male survivors",value=n_male_survived)
col3.metric("Number of female survivors",value=n_female_survived)
elif option == 'Class':
st.bar_chart(data=df,x='class',y='survived')
elif option == 'Age':
st.line_chart(data=df,x='age',y='fare')
else:
pass

def call_general():
with st.form("Run analysis"):
st.title(':blue[Iris database Analysis]')
iris = load_iris()
df = pd.DataFrame(data=iris.data, columns=iris.feature_names)
with st.expander('Display data'):
st.write(df)
option = st.radio(label='Statistics',options=['Sepal length','Sepal width','Petal length','Petal width','Clear'])

col1,col2 = st.columns(2)

if option == 'Sepal length':
col1.metric("Mean (cm)",np.round(df['sepal length (cm)'].mean(),1))
col2.metric("std (cm)",np.round(df['sepal length (cm)'].std(),1))
fig, ax = plt.subplots()
plt.hist(df['sepal length (cm)'], bins=10, edgecolor='red',histtype='step')
plt.hist(df['sepal width (cm)'], bins=10, edgecolor='grey',histtype='step')
plt.hist(df['petal length (cm)'], bins=10, edgecolor='grey',histtype='step')
plt.hist(df['petal width (cm)'], bins=10, edgecolor='grey',histtype='step')
plt.xlabel('Value')
plt.ylabel('Frequency')
plt.title('Sepal length')
st.pyplot(fig)


elif option == 'Sepal width':
col1.metric("Mean (cm)",np.round(df['sepal width (cm)'].mean(),1))
col2.metric("std (cm)",np.round(df['sepal width (cm)'].std(),1))
fig, ax = plt.subplots()
plt.hist(df['sepal length (cm)'], bins=10, edgecolor='grey',histtype='step')
plt.hist(df['sepal width (cm)'], bins=10, edgecolor='red',histtype='step')
plt.hist(df['petal length (cm)'], bins=10, edgecolor='grey',histtype='step')
plt.hist(df['petal width (cm)'], bins=10, edgecolor='grey',histtype='step')
plt.xlabel('Value')
plt.ylabel('Frequency')
plt.title('Sepal length')
st.pyplot(fig)

elif option == 'Petal length':
col1.metric("Mean (cm)",np.round(df['petal length (cm)'].mean(),1))
col2.metric("std (cm)",np.round(df['petal length (cm)'].std(),1))
fig, ax = plt.subplots()
plt.hist(df['sepal length (cm)'], bins=10, edgecolor='grey',histtype='step')
plt.hist(df['sepal width (cm)'], bins=10, edgecolor='grey',histtype='step')
plt.hist(df['petal length (cm)'], bins=10, edgecolor='red',histtype='step')
plt.hist(df['petal width (cm)'], bins=10, edgecolor='grey',histtype='step')
plt.xlabel('Value')
plt.ylabel('Frequency')
plt.title('Sepal length')
st.pyplot(fig)


elif option == 'Petal width':
col1.metric("Mean (cm)",np.round(df['petal width (cm)'].mean(),1))
col2.metric("std (cm)",np.round(df['petal width (cm)'].std(),1))
fig, ax = plt.subplots()
plt.hist(df['sepal length (cm)'], bins=10, edgecolor='grey',histtype='step')
plt.hist(df['sepal width (cm)'], bins=10, edgecolor='grey',histtype='step')
plt.hist(df['petal length (cm)'], bins=10, edgecolor='grey',histtype='step')
plt.hist(df['petal width (cm)'], bins=10, edgecolor='red',histtype='step')
plt.xlabel('Value')
plt.ylabel('Frequency')
plt.title('Sepal length')
st.pyplot(fig)


else:
pass



st.form_submit_button()

def main():
home,titanic, general = st.tabs(tabs=['Home','Titanic','Iris'])
prep_page()

with home:
st.title(':blue[Analysis]')
st.write('Here are two other tabs')
st.write('Go to :green[Titanic] to checkout some analysis on Titanic dataset')
st.write('Go to :green[Iris] tab for analysis of Iris dataset')

with titanic:
call_titanic()

with general:
call_general()

# st.snow()

# st.markdown(body='Feedback')
# with st.form("Feedback form"):
# st.write('Your rating')
# rating = st.slider("0 (bad) to 10 (excellent)",min_value=0,max_value=10,step=1)
# submitted = st.form_submit_button("Submit")

if __name__ == '__main__':
main()
38 changes: 38 additions & 0 deletions learning_projects/webapp/pages/2_Without Session State.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import streamlit as st

st.title(':blue[Visualizations]')

import streamlit as st
import seaborn as sns
import pandas as pd

def load_data():
iris = sns.load_dataset('iris')
return iris

def without_using_session_state():
data = load_data()

st.title('Interactive Data Visualization')

col1, col2 = st.columns(2,gap='large')

with col1:
st.subheader("Select Features to Plot")
available_features = data.columns[:-1]
selected_features = st.multiselect("Select features:", available_features)

with col2:
if selected_features:
st.subheader("Scatter Plot")
sns_plot = sns.pairplot(data=data, hue='species', vars=selected_features)
st.pyplot(sns_plot)



def main():
without_using_session_state()


if __name__ == '__main__':
main()
43 changes: 43 additions & 0 deletions learning_projects/webapp/pages/3_With Session State.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import streamlit as st

st.title(':blue[Visualizations]')

import streamlit as st
import seaborn as sns
import pandas as pd

def load_data():
iris = sns.load_dataset('iris')
return iris

def using_session_state():
data = load_data()

# Initialize session state if it's the first run
if 'selected_features' not in st.session_state:
st.session_state.selected_features = []

st.title("Interactive Data Visualization")

col1, col2 = st.columns(2,gap='large')

with col1:
st.subheader("Select Features to Plot")
available_features = data.columns[:-1]
selected_features = st.multiselect("Select features:", available_features, default=st.session_state.selected_features,key='manage')

st.session_state.selected_features = selected_features

with col2:
if selected_features:
st.subheader("Scatter Plot")
sns_plot = sns.pairplot(data=data, hue='species', vars=selected_features)
st.pyplot(sns_plot)


def main():
using_session_state()


if __name__ == '__main__':
main()
Loading

0 comments on commit 0a3c6f7

Please sign in to comment.