forked from Mohamed-512/Extra-Streamlit-Components
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
144 lines (113 loc) · 4.35 KB
/
main.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import streamlit as st
import extra_streamlit_components as stx
import datetime
def show_router_controls():
@st.cache(allow_output_mutation=True, hash_funcs={"_thread.RLock": lambda _: None})
def init_router():
return stx.Router({"/home": home, "/landing": landing})
def home():
return st.write("This is a home page")
def landing():
return st.write("This is the landing page")
router = init_router()
router.show_route_view()
c1, c2, c3 = st.columns(3)
with c1:
st.header("Current route")
current_route = router.get_url_route()
st.write(f"{current_route}")
with c2:
st.header("Set route")
new_route = st.text_input("route")
if st.button("Route now!"):
router.route(new_route)
with c3:
st.header("Session state")
st.write(st.session_state)
def show_cookie_manager_controls():
st.write("# Cookie Manager")
@st.cache(allow_output_mutation=True, suppress_st_warning=True)
def get_manager():
return stx.CookieManager()
cookie_manager = get_manager()
st.subheader("All Cookies:")
cookies = cookie_manager.get_all()
st.write(cookies)
c1, c2, c3 = st.columns(3)
with c1:
st.subheader("Get Cookie:")
cookie = st.text_input("Cookie", key="0")
clicked = st.button("Get")
if clicked:
value = cookie_manager.get(cookie=cookie)
st.write(value)
with c2:
st.subheader("Set Cookie:")
cookie = st.text_input("Cookie", key="1")
val = st.text_input("Value")
if st.button("Add"):
cookie_manager.set(cookie, val, expires_at=datetime.datetime(year=2022, month=2, day=2))
with c3:
st.subheader("Delete Cookie:")
cookie = st.text_input("Cookie", key="2")
if st.button("Delete"):
cookie_manager.delete(cookie)
def show_bouncing_image():
st.write("# Bouncing Image")
image_url = "https://streamlit.io/images/brand/streamlit-logo-secondary-colormark-darktext.svg"
stx.bouncing_image(image_source=image_url, animate=True,
animation_time=2000, height=145, width=500)
st.code("""
image_url = "https://streamlit.io/images/brand/streamlit-logo-secondary-colormark-darktext.svg"
stx.bouncing_image(image_source=image_url, animate=True, animation_time=2000, height=145, width=500)
""")
def show_top_bar():
st.write("# Tab Bar")
chosen_id = stx.tab_bar(data=[
stx.TabBarItemData(id=1, title="ToDo",
description="Tasks to take care of"),
stx.TabBarItemData(id=2, title="Done",
description="Tasks taken care of"),
stx.TabBarItemData(id=3, title="Overdue",
description="Tasks missed out"),
], default=1, return_type=int)
st.info(f"chosen_id = {chosen_id}, type = {type(chosen_id)}")
st.code("""
chosen_id = stx.tab_bar(data=[
stx.TabBarItemData(id=1, title="ToDo", description="Tasks to take care of"),
stx.TabBarItemData(id=2, title="Done", description="Tasks taken care of"),
stx.TabBarItemData(id=3, title="Overdue", description="Tasks missed out"),
], default=1)
""")
def show_stepper_bar():
st.write("# Stepper Bar")
c1, c2, c3 = st.columns([1, 3, 1])
with c1:
st.write("Horizontal")
with c2:
is_vertical = (st.slider("Orientation", min_value=0, max_value=1, value=0) or 0) == 1
with c3:
st.write("Vertical")
is_sequence_locked = st.checkbox("Lock Sequence", value=True)
if is_vertical:
c1, c2 = st.columns([1, 3])
with c1:
val = stx.stepper_bar(steps=["Ready", "Get Set", "Go"], is_vertical=is_vertical, lock_sequence=is_sequence_locked)
with c2:
st.info(f"Phase #{val}")
else:
val = stx.stepper_bar(steps=["Ready", "Get Set", "Go"], is_vertical=is_vertical, lock_sequence=is_sequence_locked)
st.info(f"Phase #{val}")
st.code("""
val = stx.stepper_bar(steps=["Ready", "Get Set", "Go"], is_vertical=False)
""")
if __name__ == "__main__":
# show_router_controls()
# st.write("_______")
show_cookie_manager_controls()
# st.write("_______")
# show_top_bar()
# st.write("_______")
# show_bouncing_image()
# st.write("_______")
# show_stepper_bar()