bokeh / bokeh-fastapi

BSD 3-Clause "New" or "Revised" License
9 stars 2 forks source link

Nested path not working. #24

Closed MarcSkovMadsen closed 1 month ago

MarcSkovMadsen commented 1 month ago

This is not urgent for me. But it would be super nice finally to get nested paths like /apps/panel supported with Panel enabling much nicer organisation of paths. Not being able to nest paths is quite surprising for newcomers to Panel in my experience.

import panel as pn

from fastapi import FastAPI, Request
from panel.io.fastapi import add_application

pn.extension("tabulator")

app = FastAPI()

@app.get("/")
async def read_root(request: Request):
    return {"Hello": "World", "root_path": request.scope.get("root_path")}

@add_application('/apps/panel', app=app, title='Sub Panel')
def create_panel_app():
    slider = pn.widgets.IntSlider(name='Slider', start=0, end=10, value=3)
    return slider.rx() * '๐Ÿ˜Š'
fastapi dev main.py

open http://127.0.0.1:8000/apps/panel

Watch the blank screen.

Check the server 404 error in the terminal

$ fastapi dev main.py
INFO     Using path main.py
INFO     Resolved absolute path C:\repos\awesome-panel\main.py
INFO     Searching for package file structure from directories with __init__.py files
INFO     Importing from C:\repos\awesome-panel

 โ•ญโ”€ Python module file โ”€โ•ฎ
 โ”‚                      โ”‚
 โ”‚  ๐Ÿ main.py          โ”‚
 โ”‚                      โ”‚
 โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

INFO     Importing module main
INFO     Found importable FastAPI app

 โ•ญโ”€ Importable FastAPI app โ”€โ•ฎ
 โ”‚                          โ”‚
 โ”‚  from main import app    โ”‚
 โ”‚                          โ”‚
 โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

INFO     Using import string main:app

 โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ FastAPI CLI - Development mode โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
 โ”‚                                                     โ”‚
 โ”‚  Serving at: http://127.0.0.1:8000                  โ”‚
 โ”‚                                                     โ”‚
 โ”‚  API docs: http://127.0.0.1:8000/docs               โ”‚
 โ”‚                                                     โ”‚
 โ”‚  Running in development mode, for production use:   โ”‚
 โ”‚                                                     โ”‚
 โ”‚  fastapi run                                        โ”‚
 โ”‚                                                     โ”‚
 โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

INFO:     Will watch for changes in these directories: ['C:\\repos\\awesome-panel']
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO:     Started reloader process [26728] using WatchFiles
INFO:     Started server process [40088]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     127.0.0.1:53589 - "GET / HTTP/1.1" 200 OK
INFO:     127.0.0.1:53617 - "GET /apps/panel HTTP/1.1" 200 OK
INFO:     127.0.0.1:53617 - "GET /apps/static/extensions/panel/bundled/datatabulator/tabulator-tables%406.2.1/dist/css/tabulator_simple.min.css?v=1.5.0 HTTP/1.1" 404 Not Found
INFO:     127.0.0.1:53617 - "GET /apps/static/extensions/panel/bundled/reactiveesm/es-module-shims%40%5E1.10.0/dist/es-module-shims.min.js HTTP/1.1" 404 Not Found
INFO:     127.0.0.1:53618 - "GET /apps/static/extensions/panel/bundled/datatabulator/tabulator-tables%406.2.1/dist/js/tabulator.min.js HTTP/1.1" 404 Not Found
INFO:     127.0.0.1:53619 - "GET /apps/static/extensions/panel/bundled/datatabulator/luxon/build/global/luxon.min.js HTTP/1.1" 404 Not Found
INFO:     127.0.0.1:53617 - "GET /apps/static/js/bokeh-widgets.min.js?v=a9b89524d45c9917073e9a3e35c284447f993ef108f68d4609e2b4618a4a2310af427b818b53f467ff1ece8714c2f0e8ad8f3e76361f410e292253bd271199d8 HTTP/1.1" 404 Not Found
INFO:     127.0.0.1:53618 - "GET /apps/static/js/bokeh-tables.min.js?v=fbbe15922c8405a08cc90e24b24fb8e2339900a06a31f2dc8263235cd50ea70b731c2b09f7e07d7e7460065bdb7c32d0b9a1301c9b302846688b542b8db17f6d HTTP/1.1" 404 Not Found
INFO:     127.0.0.1:53622 - "GET /apps/static/js/bokeh-gl.min.js?v=db4741fb9fd48f2bbc9938de834e307697a72bddfc4e8930c5056d0236b7261716d55c585e04a8373ed9e95da60ea8b37e93a215bc7ed5108744e649e972914f HTTP/1.1" 404 Not Found
INFO:     127.0.0.1:53621 - "GET /apps/static/js/bokeh.min.js?v=65047a94adfa94bbcbed48f015c6d04e50b19dc96ee98f9f1da3a528dd90e59cf692724ded03c9f955605b6c0f029d7460cfcade979e2633a6387c7682b0cc16 HTTP/1.1" 404 Not Found
INFO:     127.0.0.1:53620 - "GET /static/extensions/panel/panel.min.js?v=1f4dc096d58f7d21e3875671aee6f29b120ab84218fa47db2cb53bc9eb5b4dac HTTP/1.1" 200 OK

Check the errors in the browser console

image

MarcSkovMadsen commented 1 month ago

Would probably also Make it much easier to enable a full Panel based website like dash, Solara or reflex websites https://x.com/getreflex/status/1838361670361751694?s=46&t=QCeLnYcdhHHHwawHQ7y8xA.

philippjfr commented 1 month ago

Should be fixed in https://github.com/holoviz/panel/pull/7318

philippjfr commented 1 month ago

Next I would like to support path parameters.