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
# https://www.youtube.com/redirect?event=video_description&redir_token=QUFFLUhqbC1zaDlhT2staVMzaG9na2hEUElCd2RuWUpxUXxBQ3Jtc0trTmx2ZVRTYVZudUhIdW53RExDb1JMTnpZRk9DNHVhRGRSUGpWRTNja3ppRWZvWmJBbXB5U1JPT05CNmRXSy1Kd0h3N2hpdDM4UVR6MFBBV2o3ZEN4YlUzazVNR005eUpiUE92RzhlNy0yaWJnSkh6Yw&q=https%3A%2F%2Fgithub.com%2Fdataprofessor%2Fstreamlit_freecodecamp%2Ftree%2Fmain%2Fapp_10_regression_bioinformatics_solubility


for this, we need to add 3 files.
1. requirement.txt (here we put a package with its version name)
2.  procfile
3. setup.sh

login Heroku
click on new and create new app
Enter the App name
Select the region of host
in the deployment method, click on GitHub
enter the name of a repository.
if you want to deploy the changes in the app automatically as soon as you change code on GitHub then select Automatic deploy.
if you want to deploy manually then click on deploy branch

once it is successfully deployed click on the view App.


--------------------------------------------------------
# Deploy using Streamlit sharing 
https://www.youtube.com/redirect?event=video_description&redir_token=QUFFLUhqbmFMckNzcEp1Q3VrV2hqTHNlMHI2UEZwLXFPQXxBQ3Jtc0tuejF2dWVqdWt3T2xYc1dLR29XZy1JVkRMYmUzODVUYmRTVWdKTHdMY29BVFhVUngxLV9pd0hfdzg0bTNDS3cxVzBVcHJXaVJ3ZEJ0OTlBMTRJYnAzMzNlYWk4UkRycUlFYWpDWHhBME5NckExbWJWMA&q=https%3A%2F%2Fgithub.com%2Fdataprofessor%2Fpenguins-heroku

for this we'll need:
1. requirement.txt ( contains packages with its version name)

go to the share.streamlit.io website and login with GitHub.

Click on the new app button and enter the details.
Repository: Repo name
Branch: Master (depend on github)
Main file path: Streamlit app name
and click on the deploy button.







Comments