有没有办法streamlit run APP_NAME.py从 python 脚本中运行命令,它可能看起来像:
import streamlit
streamlit.run("APP_NAME.py")
由于我正在处理的项目需要跨平台(并打包),因此我不能安全地依赖对os.system(...)或的调用subprocess。
我正在使用 python 3.7 中的 Streamlit 库开发停车数据应用程序,我想使用自定义 JavaScript 进行可视化显示停车位的可用性。是否可以在 Streamlit Web 应用程序中显示 HTML/javascript 元素
目标是在后台提取实时数据(例如每 5 秒)并在需要时提取到仪表板。这是我的代码。它有点工作,但我看到两个问题: 1.如果我将 st.write("TESTING!") 移到最后,由于 while 循环,它永远不会被执行。有办法改进吗?我可以想象,随着仪表板的增长,将会有多个页面/表格等。这不会提供太多的灵活性。2. async 函数中的 return px 行,我对此不太满意,因为我通过反复试验得到了正确的结果。抱歉,我是个新手,但如果有更好的方法,我将非常感激。
谢谢你!
import asyncio
import streamlit as st
import numpy as np
st.set_page_config(layout="wide")
async def data_generator(test):
    while True:
        with test:
            px = np.random.randn(5, 1)
        await asyncio.sleep(1)
        return px
test = st.empty()
st.write("TESTING!")
with test:
    while True:
        px = asyncio.run(data_generator(test))
        st.write(px[0])
我正在尝试使用启动 Streamlit 应用程序
import os
os.popen("streamlit run stockXchange.py")
当我运行这段代码时,将会有无数个流式窗口,每 3 秒左右就会弹出一个又一个。阻止这些窗口弹出的唯一方法是完全关闭输出窗口。(我使用的是PyCharm)
这是我的代码:
import os
import streamlit as st
class Streamlit:
    def __init__(self):
        Streamlit.setup()
    def setup(self):
        st.title("StockXchange GUI")
        query = st.text_input("Enter company name:")
        if st.button("Go"):
            #calls the application function
            load(query)
if __name__ == "__main__":
    print(starttext)
    print(os.popen("streamlit run stockXchange.py").read())
    #Workaround 'missing 1 required positional argument: 'self'' Error
    Streamlit.setup(Streamlit)
我希望只弹出一个窗口,而不是无数个窗口。
有没有什么办法解决这一问题?
我正在Colab 中开发streamlit和使用ui pyngrok。一切正常,直到几天前隧道未找到错误开始发生。我正在使用下面的代码。我也升级pyngrok并尝试过,但同样的问题仍然存在。整个 UI 构建和 Colabpyngrok似乎都是最方便的学习方式。但是现在这停止工作,如果有人也可以建议任何其他方法或者我做错了什么,那就太好了
!pip install streamlit
!pip install pyngrok==4.1.1
import streamlit as st
from pyngrok import ngrok
# !ngrok authtoken (mykey)
# writefile app.py
def main():
  # app body
  pass
if __name__=='__main__':
  main()
!streamlit run app.py &>/dev/null&
public_url = ngrok.connect(port='8501')
public_url
#the log is also attached below after running above code which runs without errors as can be seen
#output below
2021-01-30 09:30:44.197 INFO    pyngrok.process: ngrok process starting: 1106
2021-01-30 …我是 Streamlit 的新手。我想进行多项选择用户输入(复选框)。但我想从 4 个选项中最多选择 3 个。
我尝试过使用 的下拉功能multiselect。
import streamlit as st
option = st.multiselect('Select three known variables:', ['initial velocity (u)', 'final velocity (v)', 'acceleration (a)', 'time (t)'])  
有用。但我认为这对于我的情况来说并不方便。另外,这里我无法将选择限制为 4 个中的 3 个。用户可以在此处选择所有 4 个选项。但我想要的代码是,如果选择了第四个选项,则前一个选择(第三个选项)将被自动取消选择。我更喜欢复选框(例如按钮)的外观radio:
import streamlit as st
option = st.radio('Select three known variables:', ['initial velocity (u)', 'final velocity (v)', 'acceleration (a)', 'time (t)'])  
但使用 时radio,我无法选择多个选项。如何编辑它,以便将其显示为复选框并且只能选择 3 个选项?
我正在尝试使用以下代码片段将我的 Medium 配置文件集成到 Streamlit 应用程序上(通过https://medium-widget.pixelpoint.io/生成)
import streamlit as st
st.markdown('''
<div id="medium-widget"></div>
<script src="https://medium-widget.pixelpoint.io/widget.js"></script>
<script>MediumWidget.Init({renderTo: '#medium-widget', params: {"resource":"https://medium.com/@mehulgupta_7991","postsPerLine":3,"limit":9,"picture":"small","fields":["description","author","claps","publishAt"],"ratio":"landscape"}})</script>''')
但看起来标签被忽略了。知道我哪里出错了吗?
我正在使用 Streamlit 制作一个基于 python 的 Web 应用程序。在Heroku中部署后,构建成功,但出现应用程序错误。我不知道源代码中的哪个位置生成了此错误。请帮我!错误 :
2022-07-18T18:55:37.985429+00:00 app[web.1]:     Inotify._raise_error()
2022-07-18T18:55:37.985439+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/watchdog/observers/inotify_c.py", line 398, in _raise_error
2022-07-18T18:55:37.985636+00:00 app[web.1]:     raise OSError(errno.ENOSPC, "inotify watch limit reached")
2022-07-18T18:55:37.985677+00:00 app[web.1]: OSError: [Errno 28] inotify watch limit reached
2022-07-18T18:55:38.387667+00:00 heroku[web.1]: Process exited with status 1
2022-07-18T18:55:38.510041+00:00 heroku[web.1]: State changed from starting to crashed
2022-07-18T18:55:48.000000+00:00 app[api]: Build succeeded
2022-07-18T18:57:33.589417+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=invezto.herokuapp.com request_id=bc8f4556-852e-4dad-8b67-71e49ffaaf23 fwd="49.37.45.19" dyno= connect= service= status=503 bytes= protocol=https
2022-07-18T18:57:33.917128+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" …我使用的是 MAC,并使用 conda-forge 下载了 Streamlit 软件包。我收到如下错误消息。
从streamlit.cli导入主ModuleNotFoundError:没有名为“streamlit.cli”的模块
我检查了一个有同样问题的 stackoverflow 帖子,它建议安装 networkx 来解决这个问题,但对我的情况没有帮助。
如果您有任何建议,请让我知道。
编辑
我根据merv的建议添加了一些更多信息。
Q. 用于安装streamlit的命令
A. conda install -c conda-forge Streamlit
问:如何激活Conda环境
A. conda create --name web-app python=3.9
conda 激活网络应用程序
问:如何启动 Python
答:我使用了 vs code 并将解释器设置为我创建的 env,并且还在 vscode 终端上激活了我创建的 env。然后我输入“streamlit hello”m,然后收到错误消息。
Q. conda列表输出
A。
该文件可用于创建环境:
$ conda 创建 --名称 --文件
平台:osx-64
abseil-cpp=20211102.0=h96cf925_1
altair=4.2.0=pyhd8ed1ab_1
appnope=0.1.3=pyhd8ed1ab_0
arrow-cpp=8.0.0=py39had1886b_0
asttokens=2.0.8=pyhd8ed1ab_0
attrs=22.1.0=pyh71513ae_1
aws-c-common=0.4.57=hb1e8313_1
aws-c-event-stream=0.1.6=h23ab428_5
aws-checksums=0.1.9=hb1e8313_0
aws-sdk-cpp=1.8.185=he271ece_0
backcall=0.2.0=pyh9f0ad1d_0
backports=1.0=py_2
backports.functools_lru_cache=1.6.4=pyhd8ed1ab_0
blinker=1.4=py_1
boost-cpp=1.80.0=h97e07a4_0
brotli=1.0.9=h5eb16cf_7
brotli-bin=1.0.9=h5eb16cf_7
brotlipy=0.7.0=py39h63b48b0_1004
bzip2=1.0.8=h0d85af4_4
c-ares=1.18.1=h0d85af4_0
ca-certificates=2022.6.15=h033912b_0
cachetools=5.2.0=pyhd8ed1ab_0
certifi=2022.6.15=pyhd8ed1ab_1
cffi=1.15.1=py39hae9ecf2_0
charset-normalizer=2.1.1=pyhd8ed1ab_0
click=8.1.3=py39h6e9494a_0
commonmark=0.9.1=py_0 …python ×10
streamlit ×10
heroku ×2
javascript ×2
anaconda ×1
button ×1
checkbox ×1
heroku-api ×1
html ×1
macos ×1
pyngrok ×1
radio-button ×1