{"id":326767,"date":"2021-07-21T09:00:44","date_gmt":"2021-07-21T09:00:44","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=326767"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=326767","title":{"rendered":"Streamlit. \u041f\u043e\u0438\u0441\u043a \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0435\u0433\u043e \u043f\u0443\u0442\u0438"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/2a4\/512\/c26\/2a4512c2602e8f2bce156ea128fdfc65.png\" width=\"602\" height=\"339\"><figcaption><\/figcaption><\/figure>\n<p>\u0421\u0430\u043c\u043e\u0435 \u0434\u043b\u0438\u043d\u043d\u043e\u0435 \u043f\u0440\u0438\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441\u043e \u0441\u043b\u043e\u0432 \u00ab\u042f \u0437\u043d\u0430\u044e \u043a\u043e\u0440\u043e\u0442\u043a\u0443\u044e \u0434\u043e\u0440\u043e\u0433\u0443\u00bb. \u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u043e \u0447\u0435\u043c \u044d\u0442\u043e? \u0427\u0438\u0442\u0430\u0439 \u0434\u0430\u043b\u044c\u0448\u0435!<\/p>\n<p>Streamlit &#8212; \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 Python \u0441 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u043c \u043a\u043e\u0434\u043e\u043c. \u041e\u043d\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441 \u043b\u0435\u0433\u043a\u043e\u0441\u0442\u044c\u044e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u043a\u0440\u0430\u0441\u0438\u0432\u044b\u0435 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0438\u043d\u0436\u0435\u043d\u0435\u0440\u043e\u0432 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f. \u0412\u0441\u0435\u0433\u043e \u0437\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0438\u043d\u0443\u0442 \u0438 \u043f\u0430\u0440\u0443 \u0441\u0442\u0440\u043e\u043a \u043a\u043e\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0442\u0438\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0414\u043b\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 Python:<\/p>\n<pre><code>pip install streamlit<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043f\u0430\u0440\u0443 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439:<\/p>\n<p>1.&nbsp;&nbsp;&nbsp; \u0421\u043e\u0437\u0434\u0430\u0442\u044c Python \u0444\u0430\u0439\u043b, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, first_app.py<\/p>\n<p>2.&nbsp;&nbsp;&nbsp; \u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <\/p>\n<p><code>import streamlit as st<\/code><\/p>\n<p>3.&nbsp;&nbsp;&nbsp; \u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043d\u0441\u043e\u043b\u044c Python<\/p>\n<p><code>streamlit run first_app.py<\/code><\/p>\n<p>&nbsp;\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0438\u043c\u0435\u0435\u0442 \u0448\u0438\u0440\u043e\u043a\u0438\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0433\u0440\u0430\u0444\u0438\u043a\u0438, \u0434\u0430\u0448\u0431\u043e\u0440\u0434\u044b \u0438 \u043a\u0430\u0440\u0442\u044b, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043a\u0440\u0430\u0441\u0438\u0432\u043e \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c DataFrame\u2019\u044b.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u043d\u0438\u0436\u0435:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1f2\/189\/7e1\/1f21897e15ec8d729e453ec6b5a02e1a.png\" alt=\"\u041f\u0440\u0438\u043c\u0435\u0440 1\" title=\"\u041f\u0440\u0438\u043c\u0435\u0440 1\" width=\"602\" height=\"273\"><figcaption>\u041f\u0440\u0438\u043c\u0435\u0440 1<\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/608\/812\/1c4\/6088121c4d20dcfe430c010ffcb85c32.png\" alt=\"\u041f\u0440\u0438\u043c\u0435\u0440 2\" title=\"\u041f\u0440\u0438\u043c\u0435\u0440 2\" width=\"602\" height=\"432\"><figcaption>\u041f\u0440\u0438\u043c\u0435\u0440 2<\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7e7\/602\/a18\/7e7602a180bded7db2353ad95f30de17.png\" alt=\"\u041f\u0440\u0438\u043c\u0435\u0440 3\" title=\"\u041f\u0440\u0438\u043c\u0435\u0440 3\" width=\"602\" height=\"336\"><figcaption>\u041f\u0440\u0438\u043c\u0435\u0440 3<\/figcaption><\/figure>\n<p>\u0414\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u043b\u0438\u0448\u044c \u043f\u0430\u0440\u0443 \u0441\u0442\u0440\u043e\u0447\u0435\u043a \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f.<\/p>\n<p>&nbsp;<\/p>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u0434\u0430\u0442\u044c \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0432\u0430\u0448\u0435\u043c\u0443 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u0432\u0435\u0441\u0442\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434:<\/p>\n<p><code>st.title('My first app')<\/code><\/p>\n<p>Streamlit \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043c\u043d\u043e\u0433\u0438\u0435 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a Matplotlib, Altair, deck.gl, Pandas \u0438 \u0434\u0440\u0443\u0433\u0438\u0435.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 DataFrame\u2019\u0430 \u0441 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Pandas \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0435\u0433\u043e, \u0438 \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u0442\u044c st.write():<\/p>\n<pre><code>df = pd.DataFrame({   'first column': [1, 2, 3, 4],   'second column': [10, 20, 30, 40] }) st.write(df)<\/code><\/pre>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c:<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/db9\/0a5\/d6a\/db90a5d6a2e1d7059ca469d4ebcdaa32.png\" width=\"287\" height=\"183\"><figcaption><\/figcaption><\/figure>\n<p>\u0415\u0441\u043b\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0432\u0438\u0434\u0435 \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0433\u043e \u0433\u0440\u0430\u0444\u0438\u043a\u0430, \u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0443:<\/p>\n<pre><code>chart_data = pd.DataFrame(      np.random.randn(20, 3),      columns=['a', 'b', 'c'])  st.line_chart(chart_data)<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/cf3\/af6\/78c\/cf3af678c2d1f62abd69afa3c3339fbb.png\" width=\"602\" height=\"273\"><figcaption><\/figcaption><\/figure>\n<p>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043c\u043c\u0430\u043d\u0434\u044b st.map() \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u0442\u043e\u0447\u043a\u0438 \u0441 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430\u043c\u0438 <\/p>\n<p>(\u0448\u0438\u0440\u043e\u0442\u0430, \u0434\u043e\u043b\u0433\u043e\u0442\u0430) \u043d\u0430 \u043a\u0430\u0440\u0442\u0435. \u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code>df = pd.DataFrame(     np.random.randn(100, 2) \/ [0.5, 0.5] + [55.5, 37.33],     columns=['lat', 'lon']) st.map(df)<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9d0\/5a7\/cf8\/9d05a7cf81a5b99b964927c2013aa7b1.png\" width=\"602\" height=\"264\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u043d\u0430 \u043a\u0430\u0440\u0442\u0435 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u044b \u043f\u0435\u0440\u0435\u0434\u0432\u0438\u0436\u0435\u043d\u0438\u0439.<\/p>\n<p>\u0414\u0430\u0442\u0430\u0441\u0435\u0442 \u0431\u044b\u043b \u0432\u0437\u044f\u0442 \u043e\u0442\u0441\u044e\u0434\u0430 <a href=\"https:\/\/data.world\/cityofaustin\/azhh-4hg8\" rel=\"noopener noreferrer nofollow\">https:\/\/data.world\/cityofaustin\/azhh-4hg8<\/a><\/p>\n<p>\u0412 \u043d\u0435\u043c \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u0441\u044f \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u044b \u043c\u0443\u0441\u043e\u0440\u043e\u0443\u0431\u043e\u0440\u043e\u0447\u043d\u044b\u0445 \u043c\u0430\u0448\u0438\u043d \u0432 \u0433\u043e\u0440\u043e\u0434\u0435 \u041e\u0441\u0442\u0438\u043d, \u0421\u0428\u0410.<\/p>\n<p>\u0411\u0443\u0434\u0435\u043c \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u044b \u0441 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0438\u0445 \u043f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u0434\u043d\u044e \u043d\u0435\u0434\u0435\u043b\u0438.<\/p>\n<p>\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043a\u043e\u043b\u043e\u043d\u043a\u0438 \u0438\u0437 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430:<\/p>\n<p>the_geom &#8212; \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0430.<\/p>\n<p>GARB_DAY &#8212; \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442 \u0434\u0435\u043d\u044c \u043d\u0435\u0434\u0435\u043b\u0438 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0430.<\/p>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0430\u0431\u043e\u0442\u044b:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8e5\/c09\/893\/8e5c098936a9848637b6ecf56aba3b28.png\" width=\"602\" height=\"279\"><figcaption><\/figcaption><\/figure>\n<p>\u041a\u0430\u0440\u0442\u0443 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0430\u0442\u044c \u0438 \u043e\u0442\u0434\u0430\u043b\u044f\u0442\u044c, \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043b\u0443\u0447\u0448\u0435 \u0438\u0437\u0443\u0447\u0438\u0442\u044c \u0442\u043e\u0442 \u0438\u043b\u0438 \u0438\u043d\u043e\u0439 \u043c\u0430\u0440\u0448\u0440\u0443\u0442.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1c8\/50f\/e06\/1c850fe061c05c991b1d944175e175c7.png\" width=\"602\" height=\"275\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b:<\/p>\n<pre><code>import pandas as pd import pydeck as pdk import streamlit as st  st.title('\u041c\u0430\u0440\u0448\u0440\u0443\u0442\u044b \u043c\u0443\u0441\u043e\u0440\u043e\u0443\u0431\u043e\u0440\u043e\u0447\u043d\u044b\u0445 \u043c\u0430\u0448\u0438\u043d \u0432 \u0433\u043e\u0440\u043e\u0434\u0435 \u041e\u0441\u0442\u0438\u043d') #\u0426\u0432\u0435\u0442\u0430 \u0434\u043b\u044f \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u043e\u0432 \u043f\u043e \u0434\u043d\u044f\u043c \u043d\u0435\u0434\u0435\u043b\u0438 colors = {         'Monday': [229,42,42],         'Thursday': [98,42,229],         'Wednesday': [42,229,61],         'Tuesday': [221,235,23],         'Friday': [144,108,26]     }  #\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u0441 \u0433\u0435\u043e\u043f\u043e\u0437\u0438\u0446\u0438\u0435\u0439 \u0432 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0443\u044e \u0444\u043e\u0440\u043c\u0443 def from_data_file(a):     res = pd.DataFrame(columns = ['latlng1','latlng2'])     for i in a:         route = i.split(', ')         for j in range(len(route)-1):             res = res.append(pd.DataFrame(data=[[route[j], route[j+1]]], columns = res.columns))     res['lon'] = res['latlng1'].apply(lambda x: float(x.split(' ')[0]))     res['lat'] = res['latlng1'].apply(lambda x: float(x.split(' ')[1]))     res['lon2'] = res['latlng2'].apply(lambda x: float(x.split(' ')[0]))     res['lat2'] = res['latlng2'].apply(lambda x: float(x.split(' ')[1]))     res['inbound'] = 100     res['outbound'] = 100     res = res.drop(['latlng1','latlng2'],1)     res = res.reset_index(drop=True)     return res  data = pd.read_csv('garbage-routes-1.csv') #\u0423\u0434\u0430\u043b\u044f\u0435\u043c \u043d\u0435\u043d\u0443\u0436\u043d\u044b\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0438\u0437 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \u0441 \u0433\u0435\u043e\u043f\u043e\u0437\u0438\u0446\u0438\u044f\u043c\u0438 data['the_geom'] = data['the_geom'].apply(lambda x: x.replace(')','').replace('(','').replace('MULTIPOLYGON ','')) data = data.set_index('GARB_DAY') days = data.index.unique() ALL_LAYERS = {} #\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u043b\u043e\u0438 \u043d\u0430 \u043a\u0430\u0440\u0442\u0443 \u043f\u043e \u0434\u043d\u044f\u043c \u043d\u0435\u0434\u0435\u043b\u0438 for i in days:     ALL_LAYERS[i] = pdk.Layer(         \"ArcLayer\",         data = from_data_file(data['the_geom'][i]),         get_source_position=[\"lon\", \"lat\"],         get_target_position=[\"lon2\", \"lat2\"],         get_source_color=colors[i],         get_target_color=colors[i],         auto_highlight=True,         width_scale=0.001,         get_width=\"outbound\",         width_min_pixels=3,         width_max_pixels=30,         ), st.sidebar.markdown('### Map Layers') selected_layers = [     layer for layer_name, layer in ALL_LAYERS.items()     if st.sidebar.checkbox(layer_name, True)] if selected_layers:     st.pydeck_chart(pdk.Deck(         map_style=\"mapbox:\/\/styles\/mapbox\/light-v10\",         initial_view_state={\"latitude\": 30.367,                             \"longitude\": -97.6, \"zoom\": 11, \"pitch\": 50},         layers=selected_layers,     )) else:     st.error(\"Please choose at least one layer above.\")<\/code><\/pre>\n<p>\u0417\u0434\u043e\u0440\u043e\u0432\u043e, \u043d\u0435 \u043f\u0440\u0430\u0432\u0434\u0430 \u043b\u0438?! \u200b<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/568836\/\"> https:\/\/habr.com\/ru\/post\/568836\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0421\u0430\u043c\u043e\u0435 \u0434\u043b\u0438\u043d\u043d\u043e\u0435 \u043f\u0440\u0438\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441\u043e \u0441\u043b\u043e\u0432 \u00ab\u042f \u0437\u043d\u0430\u044e \u043a\u043e\u0440\u043e\u0442\u043a\u0443\u044e \u0434\u043e\u0440\u043e\u0433\u0443\u00bb. \u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u043e \u0447\u0435\u043c \u044d\u0442\u043e? \u0427\u0438\u0442\u0430\u0439 \u0434\u0430\u043b\u044c\u0448\u0435!<\/p>\n<p>Streamlit &#8212; \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 Python \u0441 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u043c \u043a\u043e\u0434\u043e\u043c. \u041e\u043d\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441 \u043b\u0435\u0433\u043a\u043e\u0441\u0442\u044c\u044e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u043a\u0440\u0430\u0441\u0438\u0432\u044b\u0435 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0438\u043d\u0436\u0435\u043d\u0435\u0440\u043e\u0432 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f. \u0412\u0441\u0435\u0433\u043e \u0437\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0438\u043d\u0443\u0442 \u0438 \u043f\u0430\u0440\u0443 \u0441\u0442\u0440\u043e\u043a \u043a\u043e\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0442\u0438\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0414\u043b\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 Python:<\/p>\n<pre><code>pip install streamlit<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043f\u0430\u0440\u0443 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439:<\/p>\n<p>1.&nbsp;&nbsp;&nbsp; \u0421\u043e\u0437\u0434\u0430\u0442\u044c Python \u0444\u0430\u0439\u043b, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, first_app.py<\/p>\n<p>2.&nbsp;&nbsp;&nbsp; \u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <\/p>\n<p><code>import streamlit as st<\/code><\/p>\n<p>3.&nbsp;&nbsp;&nbsp; \u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043d\u0441\u043e\u043b\u044c Python<\/p>\n<p><code>streamlit run first_app.py<\/code><\/p>\n<p>&nbsp;\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0438\u043c\u0435\u0435\u0442 \u0448\u0438\u0440\u043e\u043a\u0438\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0433\u0440\u0430\u0444\u0438\u043a\u0438, \u0434\u0430\u0448\u0431\u043e\u0440\u0434\u044b \u0438 \u043a\u0430\u0440\u0442\u044b, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043a\u0440\u0430\u0441\u0438\u0432\u043e \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c DataFrame\u2019\u044b.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u043d\u0438\u0436\u0435:<\/p>\n<figure class=\"full-width\"><figcaption>\u041f\u0440\u0438\u043c\u0435\u0440 1<\/figcaption><\/figure>\n<figure class=\"full-width\"><figcaption>\u041f\u0440\u0438\u043c\u0435\u0440 2<\/figcaption><\/figure>\n<figure class=\"full-width\"><figcaption>\u041f\u0440\u0438\u043c\u0435\u0440 3<\/figcaption><\/figure>\n<p>\u0414\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u043b\u0438\u0448\u044c \u043f\u0430\u0440\u0443 \u0441\u0442\u0440\u043e\u0447\u0435\u043a \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f.<\/p>\n<p>&nbsp;<\/p>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u0434\u0430\u0442\u044c \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0432\u0430\u0448\u0435\u043c\u0443 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u0432\u0435\u0441\u0442\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434:<\/p>\n<p><code>st.title('My first app')<\/code><\/p>\n<p>Streamlit \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043c\u043d\u043e\u0433\u0438\u0435 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a Matplotlib, Altair, deck.gl, Pandas \u0438 \u0434\u0440\u0443\u0433\u0438\u0435.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 DataFrame\u2019\u0430 \u0441 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Pandas \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0435\u0433\u043e, \u0438 \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u0442\u044c st.write():<\/p>\n<pre><code>df = pd.DataFrame({   'first column': [1, 2, 3, 4],   'second column': [10, 20, 30, 40] }) st.write(df)<\/code><\/pre>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c:<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u0415\u0441\u043b\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0432\u0438\u0434\u0435 \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0433\u043e \u0433\u0440\u0430\u0444\u0438\u043a\u0430, \u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0443:<\/p>\n<pre><code>chart_data = pd.DataFrame(      np.random.randn(20, 3),      columns=['a', 'b', 'c'])  st.line_chart(chart_data)<\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043c\u043c\u0430\u043d\u0434\u044b st.map() \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u0442\u043e\u0447\u043a\u0438 \u0441 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430\u043c\u0438 <\/p>\n<p>(\u0448\u0438\u0440\u043e\u0442\u0430, \u0434\u043e\u043b\u0433\u043e\u0442\u0430) \u043d\u0430 \u043a\u0430\u0440\u0442\u0435. \u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code>df = pd.DataFrame(     np.random.randn(100, 2) \/ [0.5, 0.5] + [55.5, 37.33],     columns=['lat', 'lon']) st.map(df)<\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u043d\u0430 \u043a\u0430\u0440\u0442\u0435 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u044b \u043f\u0435\u0440\u0435\u0434\u0432\u0438\u0436\u0435\u043d\u0438\u0439.<\/p>\n<p>\u0414\u0430\u0442\u0430\u0441\u0435\u0442 \u0431\u044b\u043b \u0432\u0437\u044f\u0442 \u043e\u0442\u0441\u044e\u0434\u0430 <a href=\"https:\/\/data.world\/cityofaustin\/azhh-4hg8\" rel=\"noopener noreferrer nofollow\">https:\/\/data.world\/cityofaustin\/azhh-4hg8<\/a><\/p>\n<p>\u0412 \u043d\u0435\u043c \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u0441\u044f \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u044b \u043c\u0443\u0441\u043e\u0440\u043e\u0443\u0431\u043e\u0440\u043e\u0447\u043d\u044b\u0445 \u043c\u0430\u0448\u0438\u043d \u0432 \u0433\u043e\u0440\u043e\u0434\u0435 \u041e\u0441\u0442\u0438\u043d, \u0421\u0428\u0410.<\/p>\n<p>\u0411\u0443\u0434\u0435\u043c \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u044b \u0441 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0438\u0445 \u043f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u0434\u043d\u044e \u043d\u0435\u0434\u0435\u043b\u0438.<\/p>\n<p>\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043a\u043e\u043b\u043e\u043d\u043a\u0438 \u0438\u0437 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430:<\/p>\n<p>the_geom &#8212; \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0430.<\/p>\n<p>GARB_DAY &#8212; \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442 \u0434\u0435\u043d\u044c \u043d\u0435\u0434\u0435\u043b\u0438 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0430.<\/p>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0430\u0431\u043e\u0442\u044b:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041a\u0430\u0440\u0442\u0443 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0430\u0442\u044c \u0438 \u043e\u0442\u0434\u0430\u043b\u044f\u0442\u044c, \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043b\u0443\u0447\u0448\u0435 \u0438\u0437\u0443\u0447\u0438\u0442\u044c \u0442\u043e\u0442 \u0438\u043b\u0438 \u0438\u043d\u043e\u0439 \u043c\u0430\u0440\u0448\u0440\u0443\u0442.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b:<\/p>\n<pre><code>import pandas as pd import pydeck as pdk import streamlit as st  st.title('\u041c\u0430\u0440\u0448\u0440\u0443\u0442\u044b \u043c\u0443\u0441\u043e\u0440\u043e\u0443\u0431\u043e\u0440\u043e\u0447\u043d\u044b\u0445 \u043c\u0430\u0448\u0438\u043d \u0432 \u0433\u043e\u0440\u043e\u0434\u0435 \u041e\u0441\u0442\u0438\u043d') #\u0426\u0432\u0435\u0442\u0430 \u0434\u043b\u044f \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u043e\u0432 \u043f\u043e \u0434\u043d\u044f\u043c \u043d\u0435\u0434\u0435\u043b\u0438 colors = {         'Monday': [229,42,42],         'Thursday': [98,42,229],         'Wednesday': [42,229,61],         'Tuesday': [221,235,23],         'Friday': [144,108,26]     }  #\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u0441 \u0433\u0435\u043e\u043f\u043e\u0437\u0438\u0446\u0438\u0435\u0439 \u0432 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0443\u044e \u0444\u043e\u0440\u043c\u0443 def from_data_file(a):     res = pd.DataFrame(columns = ['latlng1','latlng2'])     for i in a:         route = i.split(', ')         for j in range(len(route)-1):             res = res.append(pd.DataFrame(data=[[route[j], route[j+1]]], columns = res.columns))     res['lon'] = res['latlng1'].apply(lambda x: float(x.split(' ')[0]))     res['lat'] = res['latlng1'].apply(lambda x: float(x.split(' ')[1]))     res['lon2'] = res['latlng2'].apply(lambda x: float(x.split(' ')[0]))     res['lat2'] = res['latlng2'].apply(lambda x: float(x.split(' ')[1]))     res['inbound'] = 100     res['outbound'] = 100     res = res.drop(['latlng1','latlng2'],1)     res = res.reset_index(drop=True)     return res  data = pd.read_csv('garbage-routes-1.csv') #\u0423\u0434\u0430\u043b\u044f\u0435\u043c \u043d\u0435\u043d\u0443\u0436\u043d\u044b\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0438\u0437 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \u0441 \u0433\u0435\u043e\u043f\u043e\u0437\u0438\u0446\u0438\u044f\u043c\u0438 data['the_geom'] = data['the_geom'].apply(lambda x: x.replace(')','').replace('(','').replace('MULTIPOLYGON ','')) data = data.set_index('GARB_DAY') days = data.index.unique() ALL_LAYERS = {} #\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u043b\u043e\u0438 \u043d\u0430 \u043a\u0430\u0440\u0442\u0443 \u043f\u043e \u0434\u043d\u044f\u043c \u043d\u0435\u0434\u0435\u043b\u0438 for i in days:     ALL_LAYERS[i] = pdk.Layer(         \"ArcLayer\",         data = from_data_file(data['the_geom'][i]),         get_source_position=[\"lon\", \"lat\"],         get_target_position=[\"lon2\", \"lat2\"],         get_source_color=colors[i],         get_target_color=colors[i],         auto_highlight=True,         width_scale=0.001,         get_width=\"outbound\",         width_min_pixels=3,         width_max_pixels=30,         ), st.sidebar.markdown('### Map Layers') selected_layers = [     layer for layer_name, layer in ALL_LAYERS.items()     if st.sidebar.checkbox(layer_name, True)] if selected_layers:     st.pydeck_chart(pdk.Deck(         map_style=\"mapbox:\/\/styles\/mapbox\/light-v10\",         initial_view_state={\"latitude\": 30.367,                             \"longitude\": -97.6, \"zoom\": 11, \"pitch\": 50},         layers=selected_layers,     )) else:     st.error(\"Please choose at least one layer above.\")<\/code><\/pre>\n<p>\u0417\u0434\u043e\u0440\u043e\u0432\u043e, \u043d\u0435 \u043f\u0440\u0430\u0432\u0434\u0430 \u043b\u0438?! \u200b<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/568836\/\"> https:\/\/habr.com\/ru\/post\/568836\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-326767","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/326767","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=326767"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/326767\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=326767"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=326767"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=326767"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}