Streamlit by dataprofessor
https://www.youtube.com/watch?v=JwSS70SZdyM&t=5s
import streamlit as st
# to write the text. here '#' represents heading 1 (H1). ## - H2. it follows markdown language. ref- https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet
st.write(""" # title
**this is bold** and ***This is bold and italics*** """)
# to draw the linechart
st.line_chart('column_name')
# to run the app
streamlit run app_name.py
# to show the image and expand to column width.
from PIL import Image
image= Image.open('logo.jpg')
st.image( image, use_column_width=True)
#for HR (horizontal) line.
***
# for header
st.header('this is header')
# for subheader
st.subheader('this is subheader')
# for text box. if we decrease the height then we have to scroll.
sequence_inp= ">DNA sequence\nabcde"
st.text_area("Sequence Input", sequence_inp, height=250)
# to display the dataframe.
st.write(dataframe)
or st.dataframe(dataframe)
# for title
st.title("This is the title")
# to write text in markdown.
st.markdown("""
This is simple text.
* **this will create a bold bullet point**
""")
# for the header in the sidebar.
st.sidebar.header("this is header in the sidebar")
# for the dropdown in the sidebar. lst_values is the list of values to show in the sidebar. in the selectbox, we can select only one value at a time.
st.sidebar.selectbox(''year'', lst_values)
# we can put @st.cache decorator above the function, if we want to store its cache.
# for multi select. here we can show the default selection and set the available values for selection.
st.sidebar.multiselect(''name", default_list, available_list)
# to create link (option) of downloading csv. this will create 'download csv "button.
import base64
| # https://discuss.streamlit.io/t/how-to-download-file-in-streamlit/1806 | |
| def filedownload(df): | |
| csv = df.to_csv(index=False) | |
| b64 = base64.b64encode(csv.encode()).decode() # strings <-> bytes conversions | |
| href = f'<a href="data:file/csv;base64,{b64}" download="playerstats.csv">Download CSV File</a>' | |
| return href | |
| st.markdown(filedownload(df_selected_team), unsafe_allow_html=True) |
# if we click on the button then only the graph should show up.
if st.button('Intercorrelation Heatmap'):
(logic to show after clicking on the graph)
# for the hyperlink. it will show 'Wikipedia' with a link to Wikipedia inside it.
st.markdown("""
[Wikipedia](https://www.wikipedia.org/) """
# to create the slider. here we want slider from number 1 to 5. and by default 2 is selected.
syntax: st.sidebar.slider('Name of slider', from_number, to_number, default_value)
st.sidebar.slider('Number of companies', 1, 5, 2)
# to expand the page to the full width. earlier it was centred.
st.beta_set_page_config(layout='wide')
# expandable text like we click on view more.
expander_bar= st.beta_expander('About")
expander_bar.markdown(""" this is expanded text """)
# using columns. in the streamlit update, we can use column. ex. sidebar can be 1st column, main dataframe can be 2nd and right side graph can be 3rd column.
col1= st.sidebar
col1.header('Input Options')
# for 2nd and 3rd columns.
col2, col3= st.beta_columns(2,1)
#here col2 width is 2 times greater than the column 3.
# to upload any file.
uploaded_file= st.sidebar.file_uploader('upload your input csv file', type=['csv'])
if uploaded_file is not None:
input_df= pd.read_csv(uploaded_file)
-------------------------------------------------------------------------------# deploying the Streamlit App on Heroku
Comments
Post a Comment