Spaces:
Runtime error
Runtime error
import streamlit as st | |
from pathlib import Path | |
import base64 | |
def img_to_bytes(img_path): | |
return base64.b64encode(Path(img_path).read_bytes()).decode() | |
def cs_sidebar(): | |
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) | |
st.sidebar.header('Streamlit cheat sheet') | |
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) | |
st.sidebar.markdown('__How to install and import__') | |
st.sidebar.code('$ pip install streamlit') | |
st.sidebar.code("import streamlit as st") | |
st.sidebar.markdown('__Add widgets to sidebar__') | |
st.sidebar.code("st.sidebar.<widget>") | |
st.sidebar.code("a = st.sidebar.radio('R:',[1,2])") | |
st.sidebar.markdown('__Command line__') | |
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") | |
st.sidebar.markdown('''<small>[st.cheat_sheet v1.0.0](https://github.com/daniellewisDL/streamlit-cheat-sheet) | Oct 2021</small>''', unsafe_allow_html=True) | |
def cs_body(): | |
col1, col2, col3 = st.columns(3) | |
col1.subheader('Magic commands') | |
col1.code("""# Magic commands implicitly `st.write()` | |
\'\'\' _This_ is some __Markdown__ \'\'\' | |
a=3 | |
'dataframe:', data""") | |
col1.subheader('Display text') | |
col1.code("""st.text('Fixed width text') | |
st.markdown('_Markdown_') | |
st.caption('Balloons. Hundreds of them...') | |
st.latex(r\'\'\' e^{i\pi} + 1 = 0 \'\'\') | |
st.write('Most objects') # df, err, func, keras! | |
st.write(['st', 'is <', 3]) | |
st.title('My title') | |
st.header('My header') | |
st.subheader('My sub') | |
st.code('for i in range(8): foo()')""") | |
col1.subheader('Display data') | |
col1.code("""st.dataframe(my_dataframe) | |
st.table(data.iloc[0:10]) | |
st.json({'foo':'bar','fu':'ba'}) | |
st.metric(label="Temp", value="273 K", delta="1.2 K")""") | |
col1.subheader('Display charts') | |
col1.code("""st.line_chart(data) | |
st.area_chart(data) | |
st.bar_chart(data) | |
st.pyplot(fig) | |
st.altair_chart(data) | |
st.vega_lite_chart(data) | |
st.plotly_chart(data) | |
st.bokeh_chart(data) | |
st.pydeck_chart(data) | |
st.deck_gl_chart(data) | |
st.graphviz_chart(data) | |
st.map(data)""") | |
col1.subheader('Display media') | |
col1.code("""st.image('./header.png') | |
st.audio(data) | |
st.video(data)""") | |
col2.subheader('Display interactive widgets') | |