-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpvgpgsurvey.py
290 lines (260 loc) · 9.17 KB
/
pvgpgsurvey.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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
'''
制作在线问卷调查
参考了这个:https://blog.csdn.net/qq_41200768/article/details/121073375@@@问卷系统
要用到的知识: https://getbootstrap.com, 这个是一个CSS框架, 在dash_bootstrap_components里面用到
dash_bootstrap_components 是对于 dash-core-components 的扩展, 有一些区别, 后者不包括button按钮, 不提供container
https://dash.plotly.com/dash-core-components
https://dash-bootstrap-components.opensource.faculty.ai
https://medium.com/analytics-vidhya/dash-bootstrap-bring-your-projects-to-life-in-a-beautiful-way-6b1c3bd7cfcf
https://www.datarevenue.com/en-blog/data-dashboarding-streamlit-vs-dash-vs-shiny-vs-voila
'''
import dash
from dash import Dash, html, dcc
import dash_bootstrap_components as dbc
from dash.dependencies import Input, Output, State
import json
import re
app = dash.Dash(__name__) # 两种写法,这一行可以写成app = dash.Dash(external_stylesheets=[dbc.themes.SOLAR]), 则不用下面一行了 #Darkly, Quartz, SLATE, SOLAR,具体可以参考 https://dash-bootstrap-components.opensource.faculty.ai/docs/themes/explorer/
app.config.external_stylesheets = [dbc.themes.SOLAR]
app.title = '政府绩效录入小能手 V1'
locations = ["甘肃", "陕西", "青海", "宁夏", "浙江", "四川"]
departments = ["工商", "税务", "人事", "市政", "公安", "卫生"]
app.layout = html.Div(
dbc.Container(
[
html.H1('2023年县级政府绩效评价录入系统',
style = {'color': '#b00404', 'text-align':'center'
}
),
html.Br(),
html.H2('第一部分 - 录入员个人信息',
style = {'color': '#3156de','text-align':'center'
}
),
html.Hr(),
html.P('1.姓名:'),
dbc.Input(
id = 'recorder',
placeholder = '填写录入员姓名',
autoComplete = 'off',
style = {
'width': '250px',
}
),
html.P('2.手机号码:'),
dbc.Input(
id = 'tel',
placeholder = '填写登记手机号',
autoComplete = 'off',
style = {
'width': '250px',
}
),
html.P('3.分组:'),
dbc.RadioItems(
id = 'group',
inline = True,
switch = True,
options=[
{'label': '1组', 'value': 'g1', 'color': '#b00404', 'font-size': 20},
{'label': '2组', 'value': 'g2', 'color': 'Warning', 'font-size': 20},
{'label': '3组', 'value': 'g3', 'color': '#b00404', 'font-size': 20},
{'label': '4组', 'value': 'g4', 'color': 'Success', 'font-size': 20},
],
labelStyle = {
'color': '#3156de',
'text-align': 'justify'
},
labelCheckedStyle = {
'color': '#b00404',
'text-align': 'justify'
}
),
html.P('4.录入日期:'),
dbc.Input(
id = 'date',
placeholder = '例: 20230725',
autoComplete = 'off',
style = {
'width': '250px'
}
),
html.Hr(),
html.Br(),
html.H2('第二部分 - 基本绩效信息',
style = {'color': '#3156de','text-align':'center'
}
),
html.Hr(),
html.P('5.所在省份:'),
dbc.RadioItems(
id = 'province',
inline = True,
switch = True,
options = [
{'label': item, 'value': item}
for item in list (set(locations))
],
style = {
'width': '800px'
}
),
html.Br(),
html.P('6.满意度:'),
dbc.Input(
id = 'sat-range',
placeholder = '满意度',
type = 'range',
style = {'width': '300px'},
min = 0,
max = 100,
step = 2,
),
html.P(id = 'output-range'),
html.P('7.所在城市:'),
dbc.Input(
id = 'city',
placeholder = '请直接填写,例: 兰州',
autoComplete = 'off',
style = {
'width': '250px'
}
),
html.Br(),
html.P('8.所在县:'),
dbc.Input(
id = 'county',
placeholder = '请直接填写,例: 城关',
autoComplete = 'off',
style = {
'width': '250px'
}
),
html.Br(),
html.P('9.涉及部门:'),
dbc.Checklist(
id = 'dptment',
inline = True,
switch = True,
options=[
{'label': item, 'value': item}
for item in list (set(departments))
],
# labelStyle = {
# 'color': '#3156de',
# 'text-align': 'justify'
# },
labelCheckedStyle = {
'color': '#b00404',
'text-align': 'justify'
},
style = {
'width': '400px'
}
),
html.Br(),
html.P('10.所在部门:'),
dbc.RadioItems(
id = 'career',
options = [
{'label': '科研人员', 'value': '科研人员'},
{'label': '运营', 'value': '运营'},
{'label': '数据分析师', 'value': '数据分析师'},
{'label': '算法工程师', 'value': '算法工程师'},
{'label': '大数据开发工程师', 'value': '大数据开发工程师'},
{'label': '金融分析师', 'value': '金融分析师'},
{'label': '爬虫工程师', 'value': '爬虫工程师'},
{'label': '学生', 'value': '学生'},
{'label': '其他', 'value': '其他'},
],
labelStyle = {
'color': '#3156de',
'text-align': 'justify'
},
labelCheckedStyle = {
'color': '#b00404',
'text-align': 'justify'
}
),
html.Br(),
html.H2('第三部分 - 信息核对',
style = {'color': '#3156de','text-align':'center'
}
),
html.Hr(),
html.P('9.手机号码:'),
dbc.Input(
id = 'tel',
placeholder = '填写登记手机号',
autoComplete = 'off',
style = {
'width': '250px'
}
),
html.Hr(),
html.Button(
'点击提交',
id = 'submit'
),
html.P(id = 'user-info'),
html.H6('~骄傲地由中国地方政府绩效中心开发和维护~',
style = {'color': '#ffa000','text-align':'center'
}
),
html.Hr()
],
# style = {
# 'display': 'inline-block',
# 'margin-top': '50px',
# 'margin-bottom': '200px'
# }
)
)
@app.callback(
Output('user-info', 'children'),
Input('submit', 'n_clicks'),
[
State('group', 'value'),
State('date', 'value'),
State('frequency', 'value'),
State('hobbies', 'value'),
State('tel', 'value')
],
prevent_initial_call=True
)
@app.callback(
Output('output-range', 'children'),
Input('sat-range', 'value')
)
def output_range(value):
return value
def fetch_info(n_clicks, gender, province, frequency, hobbies, tel):
if all([gender, province, frequency, hobbies, tel]):
with open(tel + '.json', mode='w', encoding='utf-8') as jf:
json.dump(
{
'gender': gender,
'recorder': recorder,
'frequency': frequency,
'hobbies': hobbies,
}, jf
)
return '填写完毕,请刷新页面!'
else:
return '信息未填写完全!'
@app.callback(
[Output('recorder', 'valid'),
Output('tel', 'valid'),
Output('tel', 'invalid')],
Input('tel', 'value'),
prevent_initial_call=True
)
def check_tel(value):
try:
if re.findall('\d+', value)[0] == value and len(value) == 11:
return True, False
except:
pass
return False, True
if __name__ == '__main__':
app.run_server(debug=True)