Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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')
|