-
Notifications
You must be signed in to change notification settings - Fork 6
/
__init__.py
195 lines (176 loc) · 5.15 KB
/
__init__.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import os
from idna import valid_contextj
import streamlit.components.v1 as components
import streamlit as st
import altair as alt
import streamlit_toggle as sts
from typing import Literal
_RELEASE = True
if not _RELEASE:
_component_func = components.declare_component(
"vertical_slider",
url="http://localhost:3001",
)
else:
parent_dir = os.path.dirname(os.path.abspath(__file__))
build_dir = os.path.join(parent_dir, "frontend/build")
_component_func = components.declare_component(
"streamlit_vertical_slider", path=build_dir
)
shape_types = Literal["circle", "square", "pill"]
def vertical_slider(
label: str = None,
key: str = None,
height: int = 200,
thumb_shape: shape_types = "circle",
step: [int, float] = 1,
default_value: [int, float] = 0,
min_value: [int, float] = 0,
max_value: [int, float] = 10,
track_color: str = "#E5E9F1",
slider_color: [str, tuple] = "#FF4B4B",
thumb_color: str = "#FF4B4B",
value_always_visible: bool = False,
):
assert thumb_shape in ["circle", "square", "pill"]
if default_value < min_value:
default_value = min_value
if thumb_shape == "circle":
thumb_height = ("0.75rem",)
thumb_style = ("inherit",)
thumb_color = thumb_color
if thumb_shape == "square":
thumb_height = ("0.75rem",)
thumb_style = ("1px",)
thumb_color = thumb_color
if thumb_shape == "pill":
thumb_height = ("0.35rem",)
thumb_style = ("0.25rem",)
thumb_color = thumb_color
if type(slider_color) == tuple:
gradient_colors = ",".join(slider_color)
slider_color = f"linear-gradient({gradient_colors})"
track_color = slider_color
opacity = 0
else:
opacity = 100
label_display = "auto" if not value_always_visible else True
vertical_slider_value = _component_func(
label=label,
key=key,
height=height,
default_value=default_value,
thumb_shape=thumb_shape,
step=step,
min_value=min_value,
max_value=max_value,
track_color=track_color,
thumb_color=thumb_color,
thumb_height=thumb_height,
thumb_style=thumb_style,
slider_color=slider_color,
opacity=opacity,
value_always_visible=label_display,
)
return vertical_slider_value if vertical_slider_value else default_value
if not _RELEASE:
import pandas as pd
st.set_page_config(layout="wide")
st.subheader("Vertical Slider")
bottom_cols = st.columns(15)
with bottom_cols[0]:
tst = vertical_slider(
label="Default Style",
height=200,
key="test_0",
default_value=550,
step=1,
min_value=0,
max_value=1500,
value_always_visible=False,
)
with bottom_cols[1]:
tst = vertical_slider(
label="Default Style + Always Visible",
height=200,
key="test_1",
default_value=550,
thumb_shape="circle",
step=1,
min_value=0,
max_value=1500,
value_always_visible=True,
)
with bottom_cols[2]:
tst = vertical_slider(
label="Pill Shaped",
height=200,
key="test_2",
default_value=550,
thumb_shape="pill",
step=1,
min_value=0,
max_value=1500,
value_always_visible=False,
)
with bottom_cols[3]:
tst = vertical_slider(
label="Square Shaped",
height=200,
key="test_3",
default_value=550,
thumb_shape="square",
step=1,
min_value=0,
max_value=1500,
value_always_visible=False,
)
with bottom_cols[4]:
tst = vertical_slider(
label="Custom Colors",
thumb_color="Red",
track_color="gray",
slider_color="orange",
height=200,
key="test_4",
default_value=550,
step=1,
min_value=0,
max_value=1500,
value_always_visible=False,
)
with bottom_cols[5]:
tst = vertical_slider(
label="Height Control",
height=400,
key="test_5",
default_value=550,
step=1,
min_value=0,
max_value=1500,
value_always_visible=False,
)
with bottom_cols[6]:
tst = vertical_slider(
height=400,
key="test_6",
default_value=550,
step=1,
min_value=0,
max_value=1500,
value_always_visible=False,
)
with bottom_cols[7]:
flt_tst = vertical_slider(
label="Gradient",
thumb_color="Red",
track_color="gray",
slider_color=("blue", "red"),
height=200,
key="test_gradient",
default_value=150.098,
step=0.09,
min_value=0,
max_value=25.500,
value_always_visible=False,
)