julien-c HF staff commited on
Commit
bdf7c94
1 Parent(s): 34bfae7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -22
app.py CHANGED
@@ -1,9 +1,23 @@
1
  """
2
  Streamlit Cheat Sheet
3
- App to summarise streamlit docs v0.81.0 for quick reference
4
- There is also an accompanying png version
 
 
 
5
  https://github.com/daniellewisDL/streamlit-cheat-sheet
6
- v0.71.0 November 2020 Daniel Lewis and Austin Chen
 
 
 
 
 
 
 
 
 
 
 
7
  """
8
 
9
  import streamlit as st
@@ -35,10 +49,11 @@ def img_to_bytes(img_path):
35
 
36
  def cs_sidebar():
37
 
38
- st.sidebar.header('Streamlit cheat sheet FTW')
 
39
 
40
  st.sidebar.markdown('''
41
- <small>Summary of the [docs](https://docs.streamlit.io/en/stable/api.html), as of [Streamlit v0.81.0](https://www.streamlit.io/).</small>
42
  ''', unsafe_allow_html=True)
43
 
44
  st.sidebar.markdown('__How to install and import__')
@@ -51,7 +66,7 @@ def cs_sidebar():
51
  st.sidebar.markdown('__Add widgets to sidebar__')
52
  st.sidebar.code('''
53
  st.sidebar.<widget>
54
- >>> a = st.sidebar.radio(\\'R:\\',[1,2])
55
  ''')
56
 
57
  st.sidebar.markdown('__Command line__')
@@ -66,13 +81,13 @@ $ streamlit --version
66
  ''')
67
 
68
  st.sidebar.markdown('__Pre-release features__')
69
- st.sidebar.markdown('[Beta and experimental features](https://docs.streamlit.io/en/0.70.0/api.html#beta-and-experimental-features)')
70
  st.sidebar.code('''
71
  pip uninstall streamlit
72
  pip install streamlit-nightly --upgrade
73
  ''')
74
 
75
- st.sidebar.markdown('''[<img src='data:image/png;base64,{}' class='img-fluid' width=32 height=32>](https://github.com/daniellewisDL/streamlit-cheat-sheet) <small>st.cheat_sheet v0.81.0 | May 2021</small>'''.format(img_to_bytes("brain.png")), unsafe_allow_html=True)
76
 
77
  return None
78
 
@@ -83,11 +98,11 @@ pip install streamlit-nightly --upgrade
83
  def cs_body():
84
  # Magic commands
85
 
86
- col1, col2, col3 = st.beta_columns(3)
87
 
88
  col1.subheader('Magic commands')
89
  col1.code('''# Magic commands implicitly `st.write()`
90
- \\'\\'\\' _This_ is some __Markdown__ \\'\\'\\'
91
  a=3
92
  'dataframe:', data
93
  ''')
@@ -98,14 +113,17 @@ a=3
98
  col1.code('''
99
  st.text('Fixed width text')
100
  st.markdown('_Markdown_') # see *
101
- st.latex(r\\'\\'\\' e^{i\\pi} + 1 = 0 \\'\\'\\')
 
102
  st.write('Most objects') # df, err, func, keras!
103
  st.write(['st', 'is <', 3]) # see *
104
  st.title('My title')
105
  st.header('My header')
106
  st.subheader('My sub')
107
  st.code('for i in range(8): foo()')
 
108
  * optional kwarg unsafe_allow_html = True
 
109
  ''')
110
 
111
  # Display data
@@ -115,6 +133,7 @@ st.code('for i in range(8): foo()')
115
  st.dataframe(my_dataframe)
116
  st.table(data.iloc[0:10])
117
  st.json({'foo':'bar','fu':'ba'})
 
118
  ''')
119
 
120
  # Display charts
@@ -149,6 +168,7 @@ st.video(data)
149
  col2.subheader('Display interactive widgets')
150
  col2.code('''
151
  st.button('Hit me')
 
152
  st.checkbox('Check me out')
153
  st.radio('Radio', [1,2,3])
154
  st.selectbox('Select', [1,2,3])
@@ -163,7 +183,7 @@ st.time_input('Time entry')
163
  st.file_uploader('File uploader')
164
  st.color_picker('Pick a color')
165
  ''')
166
- col2.write('Use widgets\\' returned values in variables:')
167
  col2.code('''
168
  >>> for i in range(int(st.number_input('Num:'))): foo()
169
  >>> if st.sidebar.selectbox('I:',['f']) == 'f': b()
@@ -182,15 +202,23 @@ st.stop()
182
 
183
  col2.subheader('Lay out your app')
184
  col2.code('''
185
- st.beta_container()
186
- st.beta_columns(spec)
187
- >>> col1, col2 = st.beta_columns(2)
 
 
188
  >>> col1.subheader('Columnisation')
189
- st.beta_expander('Expander')
190
- >>> with st.beta_expander('Expand'):
191
  >>> st.write('Juicy deets')
192
  ''')
193
 
 
 
 
 
 
 
194
 
195
  # Display code
196
 
@@ -248,17 +276,26 @@ DeltaGenerator.add_rows(data)
248
  col3.code('''
249
  @st.cache
250
  >>> @st.cache
251
- ... def foo(bar):
252
- ... # Mutate bar
253
  ... return data
254
  >>> # Executes d1 as first time
255
- >>> d1 = foo(ref1)
256
  >>> # Does not execute d1; returns cached value, d1==d2
257
- >>> d2 = foo(ref1)
258
  >>> # Different arg, so function d1 executes
259
- >>> d3 = foo(ref2)
 
260
  ''')
261
 
 
 
 
 
 
 
 
 
262
  return None
263
 
264
  # Run main()
 
1
  """
2
  Streamlit Cheat Sheet
3
+
4
+ App to summarise streamlit docs v1.0.0
5
+
6
+ There is also an accompanying png and pdf version
7
+
8
  https://github.com/daniellewisDL/streamlit-cheat-sheet
9
+
10
+ v1.0.0 October 2021
11
+
12
+ Author:
13
+ @daniellewisDL : https://github.com/daniellewisDL
14
+
15
+ Contributors:
16
+ arnaudmiribel : https://github.com/arnaudmiribel
17
+ akrolsmir : https://github.com/akrolsmir
18
+ nathancarter : https://github.com/nathancarter
19
+ epogrebnyak : https://github.com/epogrebnyak
20
+
21
  """
22
 
23
  import streamlit as st
 
49
 
50
  def cs_sidebar():
51
 
52
+ st.sidebar.markdown('''[<img src='data:image/png;base64,{}' class='img-fluid' width=32 height=32>](https://streamlit.io/)'''.format(img_to_bytes("logomark_website.png")), unsafe_allow_html=True)
53
+ st.sidebar.header('Streamlit cheat sheet')
54
 
55
  st.sidebar.markdown('''
56
+ <small>Summary of the [docs](https://docs.streamlit.io/en/stable/api.html), as of [Streamlit v1.0.0](https://www.streamlit.io/).</small>
57
  ''', unsafe_allow_html=True)
58
 
59
  st.sidebar.markdown('__How to install and import__')
 
66
  st.sidebar.markdown('__Add widgets to sidebar__')
67
  st.sidebar.code('''
68
  st.sidebar.<widget>
69
+ >>> a = st.sidebar.radio(\'R:\',[1,2])
70
  ''')
71
 
72
  st.sidebar.markdown('__Command line__')
 
81
  ''')
82
 
83
  st.sidebar.markdown('__Pre-release features__')
84
+ st.sidebar.markdown('[Beta and experimental features](https://docs.streamlit.io/en/stable/api.html#beta-and-experimental-features)')
85
  st.sidebar.code('''
86
  pip uninstall streamlit
87
  pip install streamlit-nightly --upgrade
88
  ''')
89
 
90
+ st.sidebar.markdown('''<small>[st.cheat_sheet v1.0.0](https://github.com/daniellewisDL/streamlit-cheat-sheet) | Oct 2021</small>''', unsafe_allow_html=True)
91
 
92
  return None
93
 
 
98
  def cs_body():
99
  # Magic commands
100
 
101
+ col1, col2, col3 = st.columns(3)
102
 
103
  col1.subheader('Magic commands')
104
  col1.code('''# Magic commands implicitly `st.write()`
105
+ \'\'\' _This_ is some __Markdown__ \'\'\'
106
  a=3
107
  'dataframe:', data
108
  ''')
 
113
  col1.code('''
114
  st.text('Fixed width text')
115
  st.markdown('_Markdown_') # see *
116
+ st.caption('Balloons. Hundreds of them...')
117
+ st.latex(r\'\'\' e^{i\pi} + 1 = 0 \'\'\')
118
  st.write('Most objects') # df, err, func, keras!
119
  st.write(['st', 'is <', 3]) # see *
120
  st.title('My title')
121
  st.header('My header')
122
  st.subheader('My sub')
123
  st.code('for i in range(8): foo()')
124
+
125
  * optional kwarg unsafe_allow_html = True
126
+
127
  ''')
128
 
129
  # Display data
 
133
  st.dataframe(my_dataframe)
134
  st.table(data.iloc[0:10])
135
  st.json({'foo':'bar','fu':'ba'})
136
+ st.metric(label="Temp", value="273 K", delta="1.2 K")
137
  ''')
138
 
139
  # Display charts
 
168
  col2.subheader('Display interactive widgets')
169
  col2.code('''
170
  st.button('Hit me')
171
+ st.download_button('On the dl', data)
172
  st.checkbox('Check me out')
173
  st.radio('Radio', [1,2,3])
174
  st.selectbox('Select', [1,2,3])
 
183
  st.file_uploader('File uploader')
184
  st.color_picker('Pick a color')
185
  ''')
186
+ col2.write('Use widgets\' returned values in variables:')
187
  col2.code('''
188
  >>> for i in range(int(st.number_input('Num:'))): foo()
189
  >>> if st.sidebar.selectbox('I:',['f']) == 'f': b()
 
202
 
203
  col2.subheader('Lay out your app')
204
  col2.code('''
205
+ st.form('my_form_identifier')
206
+ st.form_submit_button('Submit to me')
207
+ st.container()
208
+ st.columns(spec)
209
+ >>> col1, col2 = st.columns(2)
210
  >>> col1.subheader('Columnisation')
211
+ st.expander('Expander')
212
+ >>> with st.expander('Expand'):
213
  >>> st.write('Juicy deets')
214
  ''')
215
 
216
+ col2.write('Batch widgets together in a form:')
217
+ col2.code('''
218
+ >>> with st.form(key='my_form'):
219
+ >>> text_input = st.text_input(label='Enter some text')
220
+ >>> submit_button = st.form_submit_button(label='Submit')
221
+ ''')
222
 
223
  # Display code
224
 
 
276
  col3.code('''
277
  @st.cache
278
  >>> @st.cache
279
+ ... def fetch_and_clean_data(url):
280
+ ... # Mutate data at url
281
  ... return data
282
  >>> # Executes d1 as first time
283
+ >>> d1 = fetch_and_clean_data(ref1)
284
  >>> # Does not execute d1; returns cached value, d1==d2
285
+ >>> d2 = fetch_and_clean_data(ref1)
286
  >>> # Different arg, so function d1 executes
287
+ >>> d3 = fetch_and_clean_data(ref2)
288
+
289
  ''')
290
 
291
+ col3.subheader('Other key parts of the API')
292
+ col3.markdown('''
293
+ <small>[State API](https://docs.streamlit.io/en/stable/session_state_api.html)</small><br>
294
+ <small>[Theme option reference](https://docs.streamlit.io/en/stable/theme_options.html)</small><br>
295
+ <small>[Components API reference](https://docs.streamlit.io/en/stable/develop_streamlit_components.html)</small><br>
296
+ <small>[API cheat sheet](https://share.streamlit.io/daniellewisdl/streamlit-cheat-sheet/app.py)</small><br>
297
+ ''', unsafe_allow_html=True)
298
+
299
  return None
300
 
301
  # Run main()