awacke1 commited on
Commit
d9d1929
·
1 Parent(s): 47a37b2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +99 -61
app.py CHANGED
@@ -1,62 +1,100 @@
1
  import streamlit as st
2
- from pathlib import Path
3
- import base64
4
-
5
- def img_to_bytes(img_path):
6
- return base64.b64encode(Path(img_path).read_bytes()).decode()
7
-
8
- def cs_sidebar():
9
- st.sidebar.markdown(f'''<img src='data:image/png;base64,{img_to_bytes("logomark_website.png")}' class='img-fluid' width=32 height=32>''', unsafe_allow_html=True)
10
- st.sidebar.header('Streamlit cheat sheet')
11
- st.sidebar.markdown('''<small>Summary of the [docs](https://docs.streamlit.io/en/stable/api.html), as of [Streamlit v1.0.0](https://www.streamlit.io/).</small>''', unsafe_allow_html=True)
12
- st.sidebar.markdown('__How to install and import__')
13
- st.sidebar.code('$ pip install streamlit')
14
- st.sidebar.code("import streamlit as st")
15
- st.sidebar.markdown('__Add widgets to sidebar__')
16
- st.sidebar.code("st.sidebar.<widget>")
17
- st.sidebar.code("a = st.sidebar.radio('R:',[1,2])")
18
- st.sidebar.markdown('__Command line__')
19
- st.sidebar.code("$ streamlit --help\n$ streamlit run your_script.py\n$ streamlit hello\n$ streamlit config show\n$ streamlit cache clear\n$ streamlit docs\n$ streamlit --version")
20
- st.sidebar.markdown('''<small>[st.cheat_sheet v1.0.0](https://github.com/daniellewisDL/streamlit-cheat-sheet) | Oct 2021</small>''', unsafe_allow_html=True)
21
-
22
- def cs_body():
23
- col1, col2, col3 = st.columns(3)
24
- col1.subheader('Magic commands')
25
- col1.code("""# Magic commands implicitly `st.write()`
26
- \'\'\' _This_ is some __Markdown__ \'\'\'
27
- a=3
28
- 'dataframe:', data""")
29
- col1.subheader('Display text')
30
- col1.code("""st.text('Fixed width text')
31
- st.markdown('_Markdown_')
32
- st.caption('Balloons. Hundreds of them...')
33
- st.latex(r\'\'\' e^{i\pi} + 1 = 0 \'\'\')
34
- st.write('Most objects') # df, err, func, keras!
35
- st.write(['st', 'is <', 3])
36
- st.title('My title')
37
- st.header('My header')
38
- st.subheader('My sub')
39
- st.code('for i in range(8): foo()')""")
40
- col1.subheader('Display data')
41
- col1.code("""st.dataframe(my_dataframe)
42
- st.table(data.iloc[0:10])
43
- st.json({'foo':'bar','fu':'ba'})
44
- st.metric(label="Temp", value="273 K", delta="1.2 K")""")
45
- col1.subheader('Display charts')
46
- col1.code("""st.line_chart(data)
47
- st.area_chart(data)
48
- st.bar_chart(data)
49
- st.pyplot(fig)
50
- st.altair_chart(data)
51
- st.vega_lite_chart(data)
52
- st.plotly_chart(data)
53
- st.bokeh_chart(data)
54
- st.pydeck_chart(data)
55
- st.deck_gl_chart(data)
56
- st.graphviz_chart(data)
57
- st.map(data)""")
58
- col1.subheader('Display media')
59
- col1.code("""st.image('./header.png')
60
- st.audio(data)
61
- st.video(data)""")
62
- col2.subheader('Display interactive widgets')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import pandas as pd
3
+
4
+ # Magic commands
5
+
6
+ st.set_page_config(page_title='Streamlit Cheat Sheet')
7
+ st.set_option('deprecation.showfileUploaderEncoding', False)
8
+
9
+ col1, col2, col3 = st.columns(3)
10
+
11
+ col1.subheader('Magic commands')
12
+ col1.code('''# Magic commands implicitly `st.write()`
13
+ \'\'\' _This_ is some __Markdown__ \'\'\'
14
+ a=3
15
+ 'dataframe:', data
16
+ ''')
17
+
18
+ # Display text
19
+
20
+ col1.subheader('Display text')
21
+ col1.code('''
22
+ st.text('Fixed width text')
23
+ st.markdown('_Markdown_') # see *
24
+ st.caption('Balloons. Hundreds of them...')
25
+ st.latex(r\'\'\' e^{i\pi} + 1 = 0 \'\'\')
26
+ st.write('Most objects') # df, err, func, keras!
27
+ st.write(['st', 'is <', 3]) # see *
28
+ st.title('My title')
29
+ st.header('My header')
30
+ st.subheader('My sub')
31
+ st.code('for i in range(8): foo()')
32
+ * optional kwarg unsafe_allow_html = True
33
+ ''')
34
+
35
+ # Display data
36
+
37
+ col1.subheader('Display data')
38
+ col1.code('''
39
+ my_dataframe = pd.DataFrame({'column1': [1, 2, 3], 'column2': [4, 5, 6]})
40
+ data = pd.DataFrame({'column1': [1, 2, 3], 'column2': [4, 5, 6]})
41
+ st.dataframe(my_dataframe)
42
+ st.table(data.iloc[0:10])
43
+ st.json({'foo':'bar','fu':'ba'})
44
+ st.metric(label="Temp", value="273 K", delta="1.2 K")
45
+ ''')
46
+
47
+ # Display charts
48
+
49
+ col1.subheader('Display charts')
50
+ col1.code('''
51
+ data = pd.DataFrame({'x': [1, 2, 3], 'y': [4, 5, 6]})
52
+ fig, ax = plt.subplots()
53
+ ax.plot(data['x'], data['y'])
54
+ st.line_chart(data)
55
+ st.area_chart(data)
56
+ st.bar_chart(data)
57
+ st.pyplot(fig)
58
+ st.altair_chart(data)
59
+ st.vega_lite_chart(data)
60
+ st.plotly_chart(data)
61
+ st.bokeh_chart(data)
62
+ st.pydeck_chart(data)
63
+ st.deck_gl_chart(data)
64
+ st.graphviz_chart(data)
65
+ st.map(data)
66
+ ''')
67
+
68
+ # Display media
69
+
70
+ col1.subheader('Display media')
71
+ col1.code('''
72
+ st.image('./header.png')
73
+ st.audio(data)
74
+ st.video(data)
75
+ ''')
76
+
77
+ # Display interactive widgets
78
+
79
+ col2.subheader('Display interactive widgets')
80
+ col2.code('''
81
+ st.button('Hit me')
82
+ st.download_button('On the dl', data)
83
+ st.checkbox('Check me out')
84
+ st.radio('Radio', [1,2,3])
85
+ st.selectbox('Select', [1,2,3])
86
+ st.multiselect('Multiselect', [1,2,3])
87
+ st.slider('Slide me', min_value=0, max_value=10)
88
+ st.select_slider('Slide to select', options=[1,'2'])
89
+ st.text_input('Enter some text')
90
+ st.number_input('Enter a number')
91
+ st.text_area('Area for textual entry')
92
+ st.date_input('Date input')
93
+ st.time_input('Time entry')
94
+ st.file_uploader('File uploader')
95
+ st.color_picker('Pick a color')
96
+ ''')
97
+ col2.write('Use widgets\' returned values in variables:')
98
+ col2.code('''
99
+ for i in range(int(st.number_input('Num:'))):
100
+ foo()