Skip to content

Make model score app work on Connect/Shinyapps.io #657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 15, 2023

Conversation

jcheng5
Copy link
Collaborator

@jcheng5 jcheng5 commented Aug 4, 2023

The scoredata.begin() function gets called from the top-level of app.py, that is, at module load time. When I was testing this locally and in shinylive, it was fine to use asyncio.create_task() here, because an asyncio event loop was already started courtesy of uvicorn by the time the app module is imported. But in Connect, the app module is imported way earlier, because Connect has ASGI middleware it needs to install around it. In that case, no asyncio event loop exists and we have to do something else.

I guess another way to do this would've been to use a one-shot reactive Effect at the top level. Seems like a weird pattern to promote.

Another would be to introduce start/stop callbacks on the App object. Or app.starlette_app.add_event_handler("startup", scoredata.begin) works already, but starlette_app is not a documented attribute on App.

@jcheng5 jcheng5 requested a review from wch August 4, 2023 05:31
Copy link
Collaborator

@wch wch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. I just want to check: will the thread shut down if the app stops but Python is still running?

@jcheng5
Copy link
Collaborator Author

jcheng5 commented Aug 8, 2023

@wch It will not. I could make that work pretty easily using App.starlette_app, but that's not documented. Are you OK with me merging this as-is?

@jcheng5 jcheng5 merged commit 32b79ea into posit-dev:main Aug 15, 2023
schloerke added a commit that referenced this pull request Aug 22, 2023
* main:
  feat(Session): Make Session on_flush() and on_flushed() accept async functions (#693)
  Make data frame selection return row numbers, not pandas index value (#677)
  chore(api)!: Rename `ui.navset_pill_card` -> `ui.navset_card_pill` and `ui.navset_tab_card` -> `ui.navset_card_tab` (#681)
  Consolidate all testing into `tests/` folder (#683)
  Fix pyright error (#678)
  Make model score app work on Connect/Shinyapps.io (#657)
  Suppress type check for read_csv
  Synchonize input_file examples
  More realistic file import example (#582)
  Make flaky dataframe test have larger timeout (#675)
  Wrap bare value box value in `p` tag (#668)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants