NiceGUI - FastAPI web pages

I'm trying to deploy a NiceGUI app to Posit Connect, but it's not working.

I've tested the approach suggested here: Can I deploy a NiceGUI app to Posit Connect? - #4 by rodja using the suggested code below (by @rodja )and deploying it using rsconnect deploy fastapi -n XXXX . --entrypoint main:fastapi_app.

What I get is a checkbox that works correctly using localhost uvicorn deployment and doesn't work when I deploy to Connect. On Connect, I can click the checkbox and it registers the checked state but won't change the background color until I refresh the whole page. I don't see any errors in the Dev Console when I check/uncheck the checkbox.

from fastapi import FastAPI
from nicegui import app, ui

fastapi_app = FastAPI()

@ui.page('/')
def index():
    ui.label('Hello, FastAPI!')
    # NOTE dark mode will be persistent for each user across tabs and server restarts
    ui.dark_mode().bind_value(app.storage.user, 'dark_mode')
    ui.checkbox('dark mode').bind_value(app.storage.user, 'dark_mode')

ui.run_with(fastapi_app, storage_secret='secret')

if __name__ == '__main__':
    print('Please start with "uvicorn main:fastapi_app --reload" (if your file is named "demo.py")')

Posit Connect Logs

2024/07/16 11:29:15 AM:
[rsc-session] Content GUID: 8fa045e....
2024/07/16 11:29:15 AM:
[rsc-session] Content ID: 291
2024/07/16 11:29:15 AM:
[rsc-session] Bundle ID: 806
2024/07/16 11:29:15 AM:
[rsc-session] Job Key: syJL6aYAkN....
2024/07/16 11:29:15 AM:
Running on host: ip-10-244-0-39
2024/07/16 11:29:15 AM:
Linux distribution: Ubuntu 22.04.3 LTS (jammy)
2024/07/16 11:29:15 AM:
Running as user: ....
2024/07/16 11:29:15 AM:
Connect version: 2024.02.0
2024/07/16 11:29:15 AM:
LANG: C.UTF-8
2024/07/16 11:29:15 AM:
Working directory: /opt/rstudio-connect/mnt/app
2024/07/16 11:29:15 AM:
Bootstrapping environment using Python 3.10.12 (main, Oct  5 2023, 22:56:20) [GCC 11.4.0] at /opt/python/3.10.12/bin/python3.10
2024/07/16 11:29:15 AM:
Running content with the Python virtual environment /opt/rstudio-connect/mnt/app/python/env (/opt/rstudio-connect/mnt/python-environments/pip/3.10.12/6QrlryN-7cga0Y_Nam0Rdg)
2024/07/16 11:29:16 AM:
/opt/rstudio-connect/python/connect_fastapi_runtime.py:9: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
2024/07/16 11:29:16 AM:
  from pkg_resources import parse_version
2024/07/16 11:29:17 AM:
Running content using Python "3.10.12 (main, Oct  5 2023, 22:56:20) [GCC 11.4.0]" at "/opt/rstudio-connect/mnt/app/python/env/bin/python"
2024/07/16 11:29:17 AM:
Loading code from "main:fastapi_app"
2024/07/16 11:29:18 AM:
App type is "FastAPI"
2024/07/16 11:29:18 AM:
Starting server...
2024/07/16 11:30:12 AM:
disconnect async handler error
2024/07/16 11:30:12 AM:
Traceback (most recent call last):
2024/07/16 11:30:12 AM:
  File "/opt/rstudio-connect/mnt/app/python/env/lib/python3.10/site-packages/engineio/async_server.py", line 483, in run_async_handler
2024/07/16 11:30:12 AM:
disconnect async handler error
2024/07/16 11:30:12 AM:
    return await self.handlers[event](*args)
2024/07/16 11:30:12 AM:
Traceback (most recent call last):
2024/07/16 11:30:12 AM:
  File "/opt/rstudio-connect/mnt/app/python/env/lib/python3.10/site-packages/socketio/async_server.py", line 692, in _handle_eio_disconnect
2024/07/16 11:30:12 AM:
    await self._handle_disconnect(eio_sid, n)
2024/07/16 11:30:12 AM:
  File "/opt/rstudio-connect/mnt/app/python/env/lib/python3.10/site-packages/socketio/async_server.py", line 585, in _handle_disconnect
2024/07/16 11:30:12 AM:
    await self._trigger_event('disconnect', namespace, sid)
2024/07/16 11:30:12 AM:
  File "/opt/rstudio-connect/mnt/app/python/env/lib/python3.10/site-packages/socketio/async_server.py", line 641, in _trigger_event
2024/07/16 11:30:12 AM:
    ret = handler(*args)
2024/07/16 11:30:12 AM:
  File "/opt/rstudio-connect/mnt/app/python/env/lib/python3.10/site-packages/engineio/async_server.py", line 483, in run_async_handler
2024/07/16 11:30:12 AM:
  File "/opt/rstudio-connect/mnt/app/python/env/lib/python3.10/site-packages/nicegui/nicegui.py", line 184, in _on_disconnect
2024/07/16 11:30:12 AM:
    client.handle_disconnect()
2024/07/16 11:30:12 AM:
    return await self.handlers[event](*args)
2024/07/16 11:30:12 AM:
  File "/opt/rstudio-connect/mnt/app/python/env/lib/python3.10/site-packages/nicegui/client.py", line 268, in handle_disconnect
2024/07/16 11:30:12 AM:
    self._disconnect_task = background_tasks.create(handle_disconnect())
2024/07/16 11:30:12 AM:
  File "/opt/rstudio-connect/mnt/app/python/env/lib/python3.10/site-packages/socketio/async_server.py", line 692, in _handle_eio_disconnect
2024/07/16 11:30:12 AM:
    await self._handle_disconnect(eio_sid, n)
2024/07/16 11:30:12 AM:
  File "/opt/rstudio-connect/mnt/app/python/env/lib/python3.10/site-packages/nicegui/background_tasks.py", line 21, in create
2024/07/16 11:30:12 AM:
    assert core.loop is not None
2024/07/16 11:30:12 AM:
  File "/opt/rstudio-connect/mnt/app/python/env/lib/python3.10/site-packages/socketio/async_server.py", line 585, in _handle_disconnect
2024/07/16 11:30:12 AM:
    await self._trigger_event('disconnect', namespace, sid)
2024/07/16 11:30:12 AM:
AssertionError
2024/07/16 11:30:12 AM:
  File "/opt/rstudio-connect/mnt/app/python/env/lib/python3.10/site-packages/socketio/async_server.py", line 641, in _trigger_event
2024/07/16 11:30:12 AM:
    ret = handler(*args)
2024/07/16 11:30:12 AM:
  File "/opt/rstudio-connect/mnt/app/python/env/lib/python3.10/site-packages/nicegui/nicegui.py", line 184, in _on_disconnect
2024/07/16 11:30:12 AM:
    client.handle_disconnect()
2024/07/16 11:30:12 AM:
  File "/opt/rstudio-connect/mnt/app/python/env/lib/python3.10/site-packages/nicegui/client.py", line 268, in handle_disconnect
2024/07/16 11:30:12 AM:
    self._disconnect_task = background_tasks.create(handle_disconnect())
2024/07/16 11:30:12 AM:
  File "/opt/rstudio-connect/mnt/app/python/env/lib/python3.10/site-packages/nicegui/background_tasks.py", line 21, in create
2024/07/16 11:30:12 AM:
    assert core.loop is not None
2024/07/16 11:30:12 AM:
AssertionError

Bump. I am encountering the same issue.