yuanjie commited on
Commit
e891f47
1 Parent(s): 6207b87
_👋_.py CHANGED
@@ -1,21 +1,279 @@
1
  import streamlit as st
 
 
2
 
 
3
 
4
- def run():
5
- st.set_page_config(
6
- page_title="Hello",
7
- page_icon="👋",
8
- )
 
9
 
10
- st.write("# Welcome to AppZoo! 👋")
11
 
12
- st.markdown(
13
- """
14
- > 应用集合
15
- """
16
- )
17
 
18
 
 
 
 
 
19
 
20
- if __name__ == "__main__":
21
- run()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ from pathlib import Path
3
+ import base64
4
 
5
+ # Initial page config
6
 
7
+ st.set_page_config(
8
+ page_title='Streamlit组件清单',
9
+ page_icon="📖",
10
+ layout="wide",
11
+ initial_sidebar_state="expanded",
12
+ )
13
 
 
14
 
15
+ def main():
16
+ cs_sidebar()
17
+ cs_body()
18
+ return None
 
19
 
20
 
21
+ def img_to_bytes(img_path):
22
+ img_bytes = Path(img_path).read_bytes()
23
+ encoded = base64.b64encode(img_bytes).decode()
24
+ return encoded
25
 
26
+
27
+ # sidebar
28
+ def cs_sidebar():
29
+ st.sidebar.markdown(
30
+ '''[<img src='data:image/png;base64,{}' class='img-fluid' width=32 height=32>](https://streamlit.io/)'''.format(
31
+ img_to_bytes("logomark_website.png")), unsafe_allow_html=True)
32
+ st.sidebar.header('Streamlit组件清单')
33
+ st.sidebar.markdown('''
34
+ <small>[Streamlit文档页界面](https://docs.streamlit.io/en/stable/api.html), | [Streamlit首页](https://www.streamlit.io/).</small>
35
+ ''', unsafe_allow_html=True)
36
+ st.sidebar.markdown('__安装及引用方法__')
37
+
38
+ st.sidebar.code('pip install streamlit')
39
+
40
+ st.sidebar.markdown('引入Streamlit后的简写方法')
41
+ st.sidebar.code('import streamlit as st')
42
+
43
+ st.sidebar.markdown('__给侧边栏添加组件__')
44
+ st.sidebar.code('''
45
+ st.sidebar.<widget>
46
+ a = st.sidebar.radio(\'R:\',[1,2])
47
+ ''')
48
+
49
+ st.sidebar.markdown('__命令行__')
50
+ st.sidebar.code('''
51
+ streamlit --help
52
+ streamlit run your_script.py
53
+ streamlit hello
54
+ streamlit config show
55
+ streamlit cache clear
56
+ streamlit docs
57
+ streamlit --version
58
+ ''')
59
+
60
+ st.sidebar.markdown('__尝鲜版安装方法__')
61
+ st.sidebar.markdown('[Beta版和还在测试中功能](https://docs.streamlit.io/en/stable/api.html#beta-and-experimental-features)')
62
+ st.sidebar.code('''
63
+ pip uninstall streamlit
64
+ pip install streamlit-nightly --upgrade
65
+ ''')
66
+
67
+ st.sidebar.markdown(
68
+ '''<small>[Streamlit组件清单v1.0.0](https://github.com/daniellewisDL/streamlit-cheat-sheet) | Oct 2021</small>''',
69
+ unsafe_allow_html=True)
70
+
71
+ return None
72
+
73
+
74
+ ##########################
75
+ # 主体部分
76
+ ##########################
77
+
78
+ def cs_body():
79
+ col1, col2, col3 = st.columns(3)
80
+ col1.subheader('魔法命令')
81
+ col1.code('''# 最简单的魔法命令 `st.write()`
82
+ \'\'\' _This_ is some __Markdown__ \'\'\'
83
+ a=3
84
+ 'dataframe:', data
85
+ ''')
86
+
87
+ # Display text
88
+
89
+ col1.subheader('显示文字')
90
+ col1.code('''
91
+ st.text('固定宽度的文字')
92
+ st.markdown('_Markdown内容_') # see *
93
+ st.caption('Balloons. Hundreds of them...')
94
+ st.latex(r\'\'\' e^{i\pi} + 1 = 0 \'\'\')#嵌入公式
95
+ st.write('Most objects') # df, err, func, keras!
96
+ st.write(['st', 'is <', 3]) # see *
97
+ st.title('我的title')
98
+ st.header('我的标题')
99
+ st.subheader('我的副标题')
100
+ st.code('for i in range(8): foo()')
101
+
102
+ *可选参数 unsafe_allow_html = True
103
+
104
+ ''')
105
+
106
+ # Display data
107
+
108
+ col1.subheader('显示数据')
109
+ col1.code('''
110
+ st.dataframe(我的dataframe)
111
+ st.table(data.iloc[0:10])
112
+ st.json({'foo':'bar','fu':'ba'})
113
+ st.metric(label="Temp", value="273 K", delta="1.2 K")
114
+ ''')
115
+
116
+ # Display charts
117
+
118
+ col1.subheader('显示各类图表')
119
+ col1.code('''
120
+ st.line_chart(data)
121
+ st.area_chart(data)
122
+ st.bar_chart(data)
123
+ st.pyplot(fig)
124
+ st.altair_chart(data)
125
+ st.vega_lite_chart(data)
126
+ st.plotly_chart(data)
127
+ st.bokeh_chart(data)
128
+ st.pydeck_chart(data)
129
+ st.deck_gl_chart(data)
130
+ st.graphviz_chart(data)
131
+ st.map(data)
132
+ ''')
133
+
134
+ # Display media
135
+
136
+ col1.subheader('显示媒体文件')
137
+ col1.code('''
138
+ st.image('./header.png')
139
+ st.audio(data)
140
+ st.video(data)
141
+ ''')
142
+
143
+ # Display interactive widgets
144
+
145
+ col2.subheader('交互类组件')
146
+ col2.code('''
147
+ st.button('需要点我的时候就点我一下')
148
+ st.download_button('下载按钮', data)
149
+ st.checkbox('检查框')
150
+ st.radio('单选按钮', [1,2,3])
151
+ st.selectbox('下拉式单选', [1,2,3])
152
+ st.multiselect('多选框', [1,2,3])
153
+ st.slider('滑动选择器', min_value=0, max_value=10)
154
+ st.select_slider('滑动选择器', options=[1,'2'])
155
+ st.text_input('通过我可以输入一些文字')
156
+ st.number_input('Enter a number')
157
+ st.text_area('通过我可以输入多行文字')
158
+ st.date_input('日期选择框')
159
+ st.time_input('时间选择框')
160
+ st.file_uploader('File uploader', type=["csv","png","xlsx","json"])
161
+ st.color_picker('点我选择一种颜色')
162
+ ''')
163
+ col2.write('带返回值的组件:')
164
+ col2.code('''
165
+ for i in range(int(st.number_input('Num:'))): foo()
166
+ if st.sidebar.selectbox('I:',['f']) == 'f': b()
167
+ my_slider_val = st.slider('Quinn Mallory', 1, 88)
168
+ st.write(slider_val)
169
+ ''')
170
+
171
+ # Control flow
172
+
173
+ col2.subheader('控制流组件')
174
+ col2.code('''
175
+ st.stop()
176
+ ''')
177
+
178
+ # Lay out your app
179
+
180
+ col2.subheader('对你的APP进行布局')
181
+ col2.code('''
182
+ st.form('表单定义组件')
183
+ st.form_submit_button('表单提交按钮')
184
+ st.container()
185
+ st.columns(这里放要分几列的数字)
186
+ col1, col2 = st.columns(2)
187
+ col1.subheader('Columnisation')
188
+ st.expander('展开')
189
+ with st.expander('点我进行展开'):
190
+ st.write('次数可以写点什么')
191
+ ''')
192
+
193
+ col2.write('在表单中使用其他组件:')
194
+ col2.code('''
195
+ with st.form(key='my_form'):
196
+ text_input = st.text_input(label='Enter some text')
197
+ submit_button = st.form_submit_button(label='Submit')
198
+ ''')
199
+
200
+ # Display code
201
+
202
+ col2.subheader('显示代码')
203
+ col2.code('''
204
+ st.echo()
205
+ with st.echo():
206
+ st.write('代码将被执行并打印结果')
207
+ ''')
208
+
209
+ # Display progress and status
210
+
211
+ col3.subheader('显示进度及状态')
212
+ col3.code('''
213
+ st.progress(数字可以最大到100,意思是100%)
214
+ st.spinner()
215
+ with st.spinner(text='正在进行中'):
216
+ time.sleep(5)
217
+ st.success('完成')
218
+ st.balloons()
219
+ st.error('错误信息')
220
+ st.warning('警告信息')
221
+ st.info('通知信息')
222
+ st.success('成功信息')
223
+ st.exception(e)
224
+ ''')
225
+
226
+ # Placeholders, help, and options
227
+
228
+ col3.subheader('预设内容, 帮助及操作选项')
229
+ col3.code('''
230
+ st.empty()
231
+ my_placeholder = st.empty()
232
+ my_placeholder.text('替换完成!')
233
+ st.help(pandas.DataFrame)
234
+ st.get_option(key)
235
+ st.set_option(key, value)
236
+ st.set_page_config(page_title="streamlit", page_icon="", layout='wide')#设置页面模式
237
+ ''')
238
+
239
+ # Mutate data
240
+
241
+ col3.subheader('表格数据操作方法')
242
+ col3.code('''
243
+ DeltaGenerator.add_rows(data)
244
+ my_table = st.table(df1)
245
+ my_table.add_rows(df2)
246
+ my_chart = st.line_chart(df1)
247
+ my_chart.add_rows(df2)
248
+ ''')
249
+
250
+ # Optimize performance
251
+
252
+ col3.subheader('优化性能方法')
253
+ col3.code('''
254
+ @st.cache
255
+ ... def fetch_and_clean_data(url):
256
+ ... # Mutate data at url
257
+ ... return data
258
+ # Executes d1 as first time
259
+ d1 = fetch_and_clean_data(ref1)
260
+ # Does not execute d1; returns cached value, d1==d2
261
+ d2 = fetch_and_clean_data(ref1)
262
+ # Different arg, so function d1 executes
263
+ d3 = fetch_and_clean_data(ref2)
264
+
265
+ ''')
266
+
267
+ col3.subheader('其他API查看链接')
268
+ col3.markdown('''
269
+ <small>[State API](https://docs.streamlit.io/en/stable/session_state_api.html)</small><br>
270
+ <small>[Theme option reference](https://docs.streamlit.io/en/stable/theme_options.html)</small><br>
271
+ <small>[Components API reference](https://docs.streamlit.io/en/stable/develop_streamlit_components.html)</small><br>
272
+ <small>[API cheat sheet](https://share.streamlit.io/daniellewisdl/streamlit-cheat-sheet/app.py)</small><br>
273
+ ''', unsafe_allow_html=True)
274
+
275
+ return None
276
+
277
+
278
+ if __name__ == '__main__':
279
+ main()
pages/1000_文本标识.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # @Project : Python.
4
+ # @File : 8000_文本标识
5
+ # @Time : 2022/10/17 下午1:39
6
+ # @Author : yuanjie
7
+ # @WeChat : meutils
8
+ # @Software : PyCharm
9
+ # @Description :
10
+
11
+
12
+ import streamlit as st
13
+ from annotated_text import annotated_text, annotation
14
+
15
+ annotated_text(
16
+ "我 ",
17
+ ("热爱", "", "#8ef"),
18
+ " 我们 ",
19
+ ("非常棒", "", "#faa"),
20
+ ("而", "", "#afa"),
21
+ " 有用的 ",
22
+ ("Streamlit", "", "#fea"),
23
+ ("社区", "", "#8ef"),
24
+ ("!", "", "#afa"),
25
+ )
26
+
27
+ annotated_text(
28
+ "I ",
29
+ ("Love", "", "#8ef"),
30
+ " our ",
31
+ ("Great", "", "#faa"),
32
+ ("and", "", "#afa"),
33
+ " Useful ",
34
+ ("Streamlit", "", "#fea"),
35
+ ("Community", "", "#8ef"),
36
+ ("!", "", "#afa"),
37
+ )
pages/1001_多选组件.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # @Project : Python.
4
+ # @File : 1001_多选组件
5
+ # @Time : 2022/10/17 下午1:41
6
+ # @Author : yuanjie
7
+ # @WeChat : meutils
8
+ # @Software : PyCharm
9
+ # @Description :
10
+
11
+ import streamlit as st
12
+ from streamlit_tree_select import tree_select
13
+ nodes = [
14
+ {"label": "北京", "value": "北京"},
15
+ {
16
+ "label": "上海",
17
+ "value": "上海",
18
+ "children": [
19
+ {"label": "浦东", "value": "浦东"},
20
+ {"label": "杨浦", "value": "杨浦"},
21
+ {"label": "虹口", "value": "虹口"},
22
+ {"label": "黄浦", "value": "黄浦"},
23
+ ],
24
+ },
25
+ {
26
+ "label": "广州",
27
+ "value": "广州",
28
+ "children": [
29
+ {"label": "番禺区", "value": "番禺区"},
30
+ {
31
+ "label": "白云区",
32
+ "value": "白云区",
33
+ "children": [
34
+ {"label": "三元里街", "value": "三元里街"},
35
+ {"label": "松洲街", "value": "松洲街"},
36
+ ],
37
+ },
38
+ {"label": "珠江新区", "value": "珠江新区"},
39
+ ],
40
+ },
41
+ ]
42
+
43
+ c1, c2 = st.columns(2)
44
+
45
+ with c1:
46
+
47
+ return_select = tree_select(nodes)
48
+
49
+ with c2:
50
+ st.write(return_select["checked"])
51
+
pages/999_draw_table.py ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # @Project : Python.
4
+ # @File : 999_draw_table
5
+ # @Time : 2022/10/17 下午1:36
6
+ # @Author : yuanjie
7
+ # @WeChat : meutils
8
+ # @Software : PyCharm
9
+ # @Description :
10
+
11
+
12
+ import streamlit as st
13
+ import pandas as pd
14
+ import streamlit.components.v1 as components
15
+
16
+ st.set_page_config(page_icon="🌴", page_title="Tabulator表格", layout="wide")
17
+
18
+ file = st.file_uploader("请上传文件", type=["csv"])
19
+
20
+ if file is not None:
21
+ df = pd.read_csv(file, encoding="gbk")
22
+
23
+
24
+ def draw_table(df, height, width):
25
+ columns = df.columns
26
+ column_selection = []
27
+ column_selection.append(
28
+ """<select id="filter-field" style="font-size:15px;background:white;color:black;border-radius:15%;border-color:grey;">""")
29
+ for i in range(len(columns)):
30
+ column_selection.append(
31
+ """<option value='""" + str(columns[i]) + """'>""" + str(columns[i]) + """</option>""")
32
+ column_selection.append("""</select>""")
33
+ table_data = df.to_dict(orient="records")
34
+ column_setting = []
35
+ column_setting.append(
36
+ """{rowHandle:true, formatter:"handle", headerSort:false, frozen:true, width:30, minWidth:30}""")
37
+ for y in range(df.shape[1]):
38
+ column_setting.append(
39
+ {"title": columns[y], "field": columns[y], "width": 200, "sorter": "string", "hozAlign": "center",
40
+ "headerFilter": "input", "editor": "input"})
41
+
42
+ components.html("""
43
+ <!DOCTYPE html>
44
+ <html lang="en">
45
+ <head>
46
+ <meta charset="UTF-8">
47
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
48
+ <title>Tabulator Example</title>
49
+ <link href="https://unpkg.com/tabulator-tables@4.8.1/dist/css/tabulator_modern.min.css" rel="stylesheet">
50
+ <script type="text/javascript" src="https://unpkg.com/tabulator-tables@4.8.1/dist/js/tabulator.min.js"></script>
51
+ <script type="text/javascript" src="https://moment.github.io/luxon/global/luxon.min.js"></script>
52
+ <script type="text/javascript" src="https://oss.sheetjs.com/sheetjs/xlsx.full.min.js"></script>
53
+ </head><body>
54
+ <div style="margin-left:30%;">""" + "".join(column_selection) +
55
+ """<select id="filter-type" style="font-size:15px;background:#00ccff;color:white;border-radius:15%;border-color:white;">
56
+ <option value="like">like</option>
57
+ <option value="=">=</option>
58
+ <option value="<"><</option>
59
+ <option value="<="><=</option>
60
+ <option value=">">></option>
61
+ <option value=">=">>=</option>
62
+ <option value="!=">!=</option>
63
+ </select>
64
+ <input id="filter-value" type="text" placeholder="填写要筛选的内容" style="font-size:15px;border-color:grey;border-radius:5%">
65
+ <button id="filter-clear" style="font-size:15px;background:#00ccff;color:white;border-radius:15%;border-color:white;">清除筛选</button>
66
+ <button id="download-csv" style="font-size:15px;background:#00ccff;color:white;border-radius:15%;border-color:white;">下载CSV</button>
67
+ <button id="download-xlsx" style="font-size:15px;background:#00ccff;color:white;border-radius:15%;border-color:white;">下载XLSX</button>
68
+ <button id="download-html" style="font-size:15px;background:#00ccff;color:white;border-radius:15%;border-color:white;">下载HTML</button>
69
+ </div><script type="text/javascript">
70
+ var fieldEl = document.getElementById("filter-field");
71
+ var typeEl = document.getElementById("filter-type");
72
+ var valueEl = document.getElementById("filter-value");
73
+ function customFilter(data){
74
+ return data.car && data.rating < 3;
75
+ }function updateFilter(){
76
+ var filterVal = fieldEl.options[fieldEl.selectedIndex].value;
77
+ var typeVal = typeEl.options[typeEl.selectedIndex].value;
78
+ var filter = filterVal == "function" ? customFilter : filterVal;
79
+ if(filterVal == "function" ){
80
+ typeEl.disabled = true;
81
+ valueEl.disabled = true;
82
+ }else{
83
+ typeEl.disabled = false;
84
+ valueEl.disabled = false;
85
+ }
86
+ if(filterVal){
87
+ table.setFilter(filter,typeVal, valueEl.value);
88
+ }
89
+ }
90
+ document.getElementById("filter-field").addEventListener("change", updateFilter);
91
+ document.getElementById("filter-type").addEventListener("change", updateFilter);
92
+ document.getElementById("filter-value").addEventListener("keyup", updateFilter);
93
+ document.getElementById("filter-clear").addEventListener("click", function(){
94
+ fieldEl.value = "";
95
+ typeEl.value = "=";
96
+ valueEl.value = "";
97
+ table.clearFilter();
98
+ });
99
+ </script>
100
+ <script type="text/javascript">
101
+ var table = new Tabulator("#example-table", {
102
+ ajaxURL:"http://www.getmydata.com/now",
103
+ });
104
+ document.getElementById("download-csv").addEventListener("click", function(){
105
+ table.download("csv", "data.csv");
106
+ });
107
+ document.getElementById("download-xlsx").addEventListener("click", function(){
108
+ table.download("xlsx", "data.xlsx", {sheetName:"My Data"});
109
+ });
110
+ document.getElementById("download-html").addEventListener("click", function(){
111
+ table.download("html", "data.html", {style:true});
112
+ });
113
+ </script><div id="players" style="margin-left:16%;"></div>""" +
114
+ """<script type="text/javascript">
115
+ var tabledata = [""" + ','.join(list(map(str, table_data))) + """];""" +
116
+ """var table = new Tabulator("#players", {
117
+ height: 320,
118
+ data: tabledata,
119
+ layout: "fitDataTable",
120
+ movableRows:true,
121
+ resizableColumnFit:true,
122
+ pagination: "local",
123
+ paginationSize: 5,
124
+ tooltips: true,
125
+ columns: [""" + ','.join(list(map(str, column_setting))) + """],});</script></body></html>""",
126
+ height=height, width=width)
127
+
128
+
129
+ draw_table(df, 500, 1200)
requirements.txt CHANGED
@@ -13,3 +13,5 @@ streamlit_echarts
13
  streamlit-aggrid
14
  streamlit-agraph
15
  rdflib
 
 
 
13
  streamlit-aggrid
14
  streamlit-agraph
15
  rdflib
16
+ st-annotated-text
17
+ streamlit-tree-select