posit-dev / py-shiny

Shiny for Python
https://shiny.posit.co/py/
MIT License
1.3k stars 78 forks source link

Multi-page apps without actually exiting the page #741

Open jcheng5 opened 1 year ago

jcheng5 commented 1 year ago

Starlette routes provides one way to have multi-page apps. Another way would be to have a true SPA but have the developer experience of a multi-page app (including the URL updating as you navigate between "pages"). (Maybe each sub-app would need to be implemented as a Shiny module)

dbkegley commented 1 year ago

Related to this, can we provide a name to the ~app~ route mounted at the root / ?

I have a pyshiny app that I've added some extra routes to for oauth. From my callback route, I'd like to be able to do something like this request.url_for('shiny:index') to return back to the shiny app root from my auth callback.

routes = [
    Route('/{client_id}/login', login, name="login"),
    Route('/{client_id}/callback', callback, name="callback"),
    Mount('/', app=app_shiny, name="shiny"),
]

middleware = [
    Middleware(SessionMiddleware, secret_key=secrets.token_urlsafe(32))
]

app = Starlette(routes=routes, middleware=middleware)

If a Mount includes a name, then submounts should use a {prefix}:{name} style for reverse URL lookups. https://www.starlette.io/routing/#reverse-url-lookups

https://github.com/posit-dev/py-shiny/blob/30ef70e9f1e327d53b25175f624ce4808c6d19f2/shiny/_app.py#L178

GitHunter0 commented 4 months ago

Hey @jcheng5 , the multipage app feature is really important in my opinion. It would allow Shiny to be employed by a broader range of developers and to be a true contender for Plotly Dash. There is this workaround explained by Appsilon, however it would good to have a reliable native and tested structure to accomplish that. Congratulations for the great work so far.