Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

App.run() does not serve a mounted ASGI app (routes=[Mount(...)]) that works with uvicorn.run(app)

未关闭
#1,568 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
1-2 天
新手友好度
22/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
backend

调研方向

The App.run() docstring in lib/streamlit/web/server/starlette/starlette_app.py is the entry point, and it claims to reuse the same ASGI runner as streamlit run. Start by comparing how App.run() and uvicorn.run(app) build the Starlette routes from the routes=[Mount(...)] argument. Reproduce with the two-file example (page.py and app.py), where /bokeh/app should render "Hello from Bokeh" under app.run() as it does under uvicorn. Done means the mounted route and its websocket work under both app.run() and streamlit run.

由索引模型根据 Issue 内容生成。

描述

bug needs triage
Summary

Hi, I want to update my virtual observatory app (https://specsy.streamlit.app/) so that the user can download data selections from a Bokeh figure.

I have managed to get a working version by embedding a Bokeh server app (Bokeh 3.10 BokehASGI) in the Streamlit app via st.App(..., routes=[Mount("/bokeh", app=bokeh_app)]). When I serve the st.App with uvicorn.run(app), the mounted app works: the Bokeh page renders and its websocket callbacks run. When I start the same object with app.run(), the mounted route returns a blank white page.

Is mounting ASGI sub-applications via routes meant to be supported by App.run() and by streamlit run for st.App scripts? The App.run() docstring says it "reuses the same embedded ASGI server runner that streamlit run uses for st.App scripts".

The reason I am asking is that Streamlit Community Cloud launches apps with streamlit run, so I cannot use uvicorn.run(app) there. I would like a uniform Streamlit app for both the online and the offline installation.

Minimal reproducible example

page.py

import streamlit as st

st.write("Embedded Bokeh app below:")
st.iframe("/bokeh/app", height=300)

app.py

import sys

import streamlit as st
from starlette.routing import Mount
from bokeh.models import Div
from bokeh.server.asgi import BokehASGI


def bkapp(doc):
    doc.add_root(Div(text="Hello from Bokeh"))


bokeh_app = BokehASGI({"/app": bkapp})
app = st.App("page.py", routes=[Mount("/bokeh", app=bokeh_app)])

if __name__ == "__main__":
    if "--uvicorn" in sys.argv:
        import uvicorn
        uvicorn.run(app, host="localhost", port=8501)   # works
    else:
        app.run()                                       # mounted route is blank

Steps to reproduce

  1. python app.py --uvicorn and open http://localhost:8501/bokeh/app: "Hello from Bokeh" is shown, and the iframe in the Streamlit page also shows it.
  2. python app.py and open the same URL: blank white page, and the iframe in the Streamlit page is empty.

Expected behaviour

app.run() serves the routes passed to st.App(routes=...), including mounted ASGI apps with websockets, the same way uvicorn.run(app) does. I'd expect the same behaviour with streamlit run app.py.

Additional information

  • No errors in the terminal.

Environment

  • Streamlit: 1.65.0
  • Bokeh: 3.10.0
  • Python: 3.13
  • OS: Linux
  • Browser: Firefox

Thanks a lot for any advice.

主要语言
JavaScript
星标
178
派生
708
平均合并
1 天 21 小时
30 天内合并 PR
19

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

  • 没有 Dockerfile 或 Docker Compose 文件
  • 有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

streamlit/docs 的其他 Issue

查看 streamlit/docs 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。