{"id":1961,"date":"2023-11-29T15:04:58","date_gmt":"2023-11-29T07:04:58","guid":{"rendered":"http:\/\/zhang.mba\/?p=1961"},"modified":"2023-11-29T15:07:06","modified_gmt":"2023-11-29T07:07:06","slug":"streamlit-yi-ge-chao-ku-de-python-ku","status":"publish","type":"post","link":"https:\/\/zhang.mba\/index.php\/2023\/11\/29\/15\/04\/58\/1961\/streamlit-yi-ge-chao-ku-de-python-ku\/python\/zhangzhiqi\/","title":{"rendered":"streamlit\uff0c\u5c06\u6570\u636e\u811a\u672c\u8f6c\u53d8\u4e3a\u53ef\u5171\u4eab\u7684 Web \u5e94\u7528\u7a0b\u5e8f"},"content":{"rendered":"<p><strong>streamlit<\/strong><\/p>\n<p><strong><a href=\"https:\/\/github.com\/streamlit\/streamlit\">https:\/\/github.com\/streamlit\/streamlit<\/a><\/strong><\/p>\n<p>Streamlit \u662f\u4e00\u4e2a\u5f00\u6e90\u7684 python \u5e93\uff0c<strong>\u53ef\u8ba9\u4f60\u5728\u51e0\u5206\u949f\u5185\u5c06\u6570\u636e\u811a\u672c\u8f6c\u53d8\u4e3a\u53ef\u5171\u4eab\u7684 Web \u5e94\u7528\u7a0b\u5e8f\u3002<\/strong><\/p>\n<h3><a id=\"streamlit%E7%9A%84%E7%89%B9%E7%82%B9\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>Streamlit \u7684\u7279\u70b9<\/h3>\n<ul>\n<li>\n<p><strong>\u6613\u7528\u6027<\/strong>\uff1a\u53ea\u9700\u51e0\u884c\u4ee3\u7801\uff0c\u7528\u6237\u5c31\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u6f02\u4eae\u7684\u6570\u636e\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u6570\u636e\u79d1\u5b66\u53cb\u597d<\/strong>\uff1a\u4e0e Pandas\u3001NumPy\u3001Matplotlib \u7b49\u6d41\u884c\u7684 Python \u6570\u636e\u79d1\u5b66\u5e93\u65e0\u7f1d\u96c6\u6210\u3002<\/p>\n<\/li>\n<li>\n<p><strong>Python \u5316<\/strong>\uff1a\u5b83\u5b8c\u5168\u57fa\u4e8e Python\uff0c\u4e0d\u9700\u8981\u989d\u5916\u5b66\u4e60\u524d\u7aef\u6280\u672f\u5982 HTML \u6216 JavaScript\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u5feb\u901f\u539f\u578b\u5236\u4f5c<\/strong>\uff1aStreamlit \u975e\u5e38\u9002\u5408\u5feb\u901f\u5f00\u53d1\u539f\u578b\uff0c\u53ef\u4ee5\u5b9e\u65f6\u67e5\u770b\u4ee3\u7801\u66f4\u6539\u7684\u6548\u679c\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u4e30\u5bcc\u7684\u7ec4\u4ef6\u5e93<\/strong>\uff1aStreamlit \u5305\u542b\u591a\u79cd\u5185\u7f6e\u7ec4\u4ef6\uff0c\u5982\u6587\u672c\u8f93\u5165\u3001\u56fe\u8868\u3001\u5730\u56fe\u7b49\uff0c\u8fd8\u652f\u6301\u81ea\u5b9a\u4e49\u7ec4\u4ef6\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u6570\u636e\u4ea4\u4e92\u6027<\/strong>\uff1a\u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u4ea4\u4e92\u5f0f\u5730\u5c55\u793a\u6570\u636e\uff0c\u5982\u9009\u62e9\u6846\u3001\u6ed1\u5757\u7b49\uff0c\u4f7f\u5f97\u6570\u636e\u5206\u6790\u66f4\u52a0\u76f4\u89c2\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u5206\u4eab\u548c\u90e8\u7f72<\/strong>\uff1a\u6613\u4e8e\u5206\u4eab\u548c\u90e8\u7f72\uff0c\u53ef\u4ee5\u5feb\u901f\u5c06\u5e94\u7528\u90e8\u7f72\u5230\u4e91\u7aef\u6216\u670d\u52a1\u5668\u3002<\/p>\n<\/li>\n<\/ul>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/mmbiz.qpic.cn\/mmbiz_png\/ibPqnScajrbFPrlLxFP78waUVBSvLeBuwGdSrN0ONvPz5YKbAqHictMu3OLBHEk7qeHbLGdeanTeyGNMIUMThQTA\/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  data-original=\"https:\/\/mmbiz.qpic.cn\/mmbiz_png\/ibPqnScajrbFPrlLxFP78waUVBSvLeBuwGdSrN0ONvPz5YKbAqHictMu3OLBHEk7qeHbLGdeanTeyGNMIUMThQTA\/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\u56fe\u7247\" \/><\/div><\/p>\n<h3><a id=\"%E5%88%9D%E4%BD%93%E9%AA%8C\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u521d\u4f53\u9a8c<\/h3>\n<h4><a id=\"%E5%BA%93%E7%9A%84%E5%AE%89%E8%A3%85\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u5e93\u7684\u5b89\u88c5<\/h4>\n<p>\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528 pip \u6765\u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-python\">pip\u00a0install\u00a0streamlit\n<\/code><\/pre>\n<h4><a id=\"%E7%AE%80%E5%8D%95%E6%A1%88%E4%BE%8B\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u7b80\u5355\u6848\u4f8b<\/h4>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u521b\u5efa\u4e00\u4e2a\u65b0\u6587\u4ef6\uff0capp.py<\/p>\n<pre class=\"line-numbers\"><code class=\"language-python\">import streamlit as st\nx = st.slider(&quot;Select a value&quot;)\nst.write(x, &quot;squared is&quot;, x * x)\n<\/code><\/pre>\n<p>\u7136\u540e\u5728\u7ec8\u7aef\u6267\u884c\u5982\u4e0b\u547d\u4ee4\u5373\u53ef\u542f\u52a8\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-python\">streamlit\u00a0run\u00a0app.py\n<\/code><\/pre>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/mmbiz.qpic.cn\/mmbiz_gif\/ibPqnScajrbFPrlLxFP78waUVBSvLeBuwFyvZcVssqvzPSXIMNQbzxnHIiclR6C59HR43dcpXib47TasPJMbwkglQ\/640?wx_fmt=gif&amp;wxfrom=5&amp;wx_lazy=1'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  data-original=\"https:\/\/mmbiz.qpic.cn\/mmbiz_gif\/ibPqnScajrbFPrlLxFP78waUVBSvLeBuwFyvZcVssqvzPSXIMNQbzxnHIiclR6C59HR43dcpXib47TasPJMbwkglQ\/640?wx_fmt=gif&amp;wxfrom=5&amp;wx_lazy=1\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\u56fe\u7247\" \/><\/div><\/p>\n<h4><a id=\"%E5%A4%8D%E6%9D%82%E6%A1%88%E4%BE%8B\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u590d\u6742\u6848\u4f8b<\/h4>\n<p>streamlit \u8fd8\u652f\u6301\u5730\u56fe\u7ec4\u4ef6\uff0c\u4e0b\u9762\u6211\u4eec\u4f7f\u7528 st.map \u6765\u663e\u793a\u5317\u4eac\u7684\u5730\u56fe\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-python\">import pandas as pd\nimport streamlit as st\n\n\ndef app():\n    st.title(&quot;\u5317\u4eac\u5730\u56fe&quot;)\n\n    # \u5317\u4eac\u5e02\u4e2d\u5fc3\u7684\u7ecf\u7eac\u5ea6\n    beijing_coords = [[39.9042, 116.4074]]\n    df=pd.DataFrame(beijing_coords,columns=['lat','lon'])\n    # \u4f7f\u7528 st.map \u663e\u793a\u5730\u56fe\n    st.map(df, zoom=11)\nif __name__ == &quot;__main__&quot;:\n    app()\n<\/code><\/pre>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/mmbiz.qpic.cn\/mmbiz_png\/ibPqnScajrbFPrlLxFP78waUVBSvLeBuwnb8WwsrkDhcjkaoO1sXLGUGdGH0K28iccWpPauFooQuV1iar7VSUpxMA\/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  data-original=\"https:\/\/mmbiz.qpic.cn\/mmbiz_png\/ibPqnScajrbFPrlLxFP78waUVBSvLeBuwnb8WwsrkDhcjkaoO1sXLGUGdGH0K28iccWpPauFooQuV1iar7VSUpxMA\/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\u56fe\u7247\" \/><\/div><\/p>\n<p>\u6765\u6e90&#8212;&#8212;\u7a0b\u5e8f\u5458\u5c0f\u5bd2<\/p>\n<!--CusAds0-->\n<div style=\"font-size: 0px; height: 0px; line-height: 0px; margin: 0; padding: 0; clear: both;\"><\/div>","protected":false},"excerpt":{"rendered":"<p>streamlit https:\/\/github.com\/streamlit\/streamlit Streamlit \u662f\u4e00\u4e2a\u5f00\u6e90\u7684 python \u5e93\uff0c\u53ef\u8ba9\u4f60\u5728\u51e0\u5206\u949f\u5185\u5c06\u6570\u636e\u811a\u672c\u8f6c\u53d8\u4e3a\u53ef\u5171\u4eab\u7684 Web \u5e94\u7528\u7a0b\u5e8f\u3002 Streamlit \u7684\u7279\u70b9 \u6613\u7528\u6027\uff1a\u53ea\u9700\u51e0\u884c\u4ee3\u7801\uff0c\u7528\u6237\u5c31\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u6f02\u4eae\u7684\u6570\u636e\u5e94\u7528\u7a0b\u5e8f\u3002 \u6570\u636e\u79d1\u5b66\u53cb\u597d\uff1a &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0},"categories":[12],"tags":[],"_links":{"self":[{"href":"https:\/\/zhang.mba\/index.php\/wp-json\/wp\/v2\/posts\/1961"}],"collection":[{"href":"https:\/\/zhang.mba\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhang.mba\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhang.mba\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhang.mba\/index.php\/wp-json\/wp\/v2\/comments?post=1961"}],"version-history":[{"count":0,"href":"https:\/\/zhang.mba\/index.php\/wp-json\/wp\/v2\/posts\/1961\/revisions"}],"wp:attachment":[{"href":"https:\/\/zhang.mba\/index.php\/wp-json\/wp\/v2\/media?parent=1961"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhang.mba\/index.php\/wp-json\/wp\/v2\/categories?post=1961"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhang.mba\/index.php\/wp-json\/wp\/v2\/tags?post=1961"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}