-
Notifications
You must be signed in to change notification settings - Fork 41
/
dash_reusable_components.py
99 lines (79 loc) · 2.36 KB
/
dash_reusable_components.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
from textwrap import dedent
import dash_core_components as dcc
import dash_html_components as html
# Display utility functions
def _merge(a, b):
return dict(a, **b)
def _omit(omitted_keys, d):
return {k: v for k, v in d.items() if k not in omitted_keys}
# Custom Display Components
def Card(children, **kwargs):
return html.Section(
className='card',
children=children,
style=_merge({
'padding': 20,
'margin': 5,
# Remove possibility to select the text for better UX
'user-select': 'none',
'-moz-user-select': 'none',
'-webkit-user-select': 'none',
'-ms-user-select': 'none'
}, kwargs.get('style', {})),
**_omit(['style'], kwargs)
)
def FormattedSlider(**kwargs):
return html.Div(
style=kwargs.get('style', {}),
children=dcc.Slider(**_omit(['style'], kwargs))
)
def NamedSlider(name, **kwargs):
return html.Div(
style={'padding': '20px 10px 25px 4px'},
children=[
html.P(f'{name}:'),
html.Div(
style={'margin-left': '6px'},
children=dcc.Slider(**kwargs)
)
]
)
def NamedDropdown(name, **kwargs):
return html.Div(
style={'margin': '10px 0px'},
children=[
html.P(
children=f'{name}:',
style={'margin-left': '3px'}
),
dcc.Dropdown(**kwargs)
]
)
def NamedRadioItems(name, **kwargs):
return html.Div(
style={'padding': '20px 10px 25px 4px'},
children=[
html.P(children=f'{name}:'),
dcc.RadioItems(**kwargs)
]
)
# Non-generic
def DemoDescription(filename, strip=False):
with open(filename, 'r') as file:
text = file.read()
if strip:
text = text.split('<Start Description>')[-1]
text = text.split('<End Description>')[0]
return html.Div(
className='row',
style={
'padding': '15px 30px 27px',
'margin': '45px auto 45px',
'width': '80%',
'max-width': '1024px',
'borderRadius': 5,
'border': 'thin lightgrey solid',
'font-family': 'Roboto, sans-serif'
},
children=dcc.Markdown(dedent(text))
)