Skip to content

[bug]: starlette request object does not have the query parameters in shinylive #1794

@JoseBlanca

Description

@JoseBlanca

I want to access the query parameters to configure my app UI and behavior according to them.

To get the query parameters I have followed the method given in this comment.

A test App.

from shiny import App, ui, render


def app_ui(request):
    ui_elements = []
    ui_elements.append(ui.p(f"request: {request}"))

    url_query = request.url.query
    ui_elements.append(ui.p(f"url_query: {url_query}"))

    greeting = request.query_params.get("param")
    ui_elements.append(f"param: {greeting}")

    return ui.page_fixed(ui_elements)


def server(inputs, outputs, sessions):
    @render.code
    def greeting():
        return "Hi!."


app = App(app_ui, server)

While I was developing my App inside Visual Studio Code I was getting the correct result:

URL: http://localhost:32997/?param=hi
Html ouput:

request: <starlette.requests.Request object at 0x7f7d26702600>
url_query: param=hi&vscodeBrowserReqId=1733558209861
param: hi

Serving the App with uvicorn also works as expected.

Shell command:$ uv run uvicorn app:app
URL: http://127.0.0.1:8000/?param=hi
Html ouput:

request: <starlette.requests.Request object at 0x7fe7578c7770>
url_query: param=hi
param: hi

However, when I try to use shiny live, and that was my original intention, I loose the query parameters.

Shell command:$ rm -r tmp_shiny_site; uv run shinylive export src/apps/request_test_app/ tmp_shiny_site/; uv run python -m http.server --directory tmp_shiny_site --bind localhost 8008
URL: http://[::1]:8008/?param=hi
Html ouput:

request: <starlette.requests.Request object at 0x104e330>
url_query:
param: None

Best,

Jose Blanca

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions