-
Notifications
You must be signed in to change notification settings - Fork 2
/
demo.py
95 lines (61 loc) · 2.74 KB
/
demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
"""
this is the main file, the only file in which the magic commands will work
the loader is used in order to load the scripts demonstrating each widget
"""
import streamlit as st
from loader import load_components
import time
# page conf
st.set_page_config(
page_title="Quick reference",
page_icon="🐍",
layout="centered", # wide
initial_sidebar_state="auto") # collapsed
# process page load duration
page_load_start_time = time.time()
st.sidebar.radio('Check load time', ('switch from one button to the other', 'in order to reinterpret the code'))
page_load_time_placeholder = st.sidebar.empty()
def magic_function():
"""
the magic command syntax only works in the main file
other files require the usage of st.write or st.markdown
"""
st.markdown('# Streamlit quick reference')
st.info("""
References:
- [Streamlit API reference](https://docs.streamlit.io/en/stable/api.html)
- [Streamlit cheat sheet](https://share.streamlit.io/daniellewisdl/streamlit-cheat-sheet/app.py)
""")
st.write('<a name="Import"></a>', unsafe_allow_html=True)
'# Import'
st.code("import streamlit as st")
st.write('<a name="Magic commands"></a>', unsafe_allow_html=True)
'# Magic commands'
'All strings or objects in the **main** script file will automatically be rendered in the page by streamlit as if `st.write` or `st.mardown` were used. This only works in the main file, other script files need to use `st.write` or `st.markdown` in order to display objects or text'
with st.echo():
'some text or **markdown**'
{
'hello': True
}
st.write('<a name="Inline documentation"></a>', unsafe_allow_html=True)
'# Inline documentation'
'Any streamlit method called without parenthesis and arguments will display its documentation'
with st.echo():
st.echo
st.write('<a name="Echo"></a>', unsafe_allow_html=True)
'# Echo'
'Allows to display a block of code and then execute it. This is what is used on this page in order to demonstrate the usage of the various streamlit elements'
with st.echo():
with st.echo():
st.write('hello 👋')
# load components from script files
load_components(magic_function)
# about
st.sidebar.write("# About")
st.sidebar.info("""
This app was created using [Streamlit](https://streamlit.io/)
The code of the page is visible [here](https://github.com/lewagon/streamlit). If you are just getting started, an older yet simpler version of the code is available [here](https://github.com/gmanchon/streamlit/tree/main)
""")
# show page load duration in sidebar
page_load_duration = time.time() - page_load_start_time
page_load_time_placeholder.markdown(f'{round(page_load_duration, 3)} seconds')