Skip to content

Conversation

wch
Copy link
Collaborator

@wch wch commented Nov 17, 2023

For running Express apps, this PR makes it so that setting an environment variable is no longer needed for uvicorn to launch the app; instead, if the app path is:

path/to/app.py

then this sets the entrypoint to

shiny.express.app:path_2f_to_2f_app_2e_py

This will make it possible to deploy on shinyapps.io.

The escaping rule is this:

  • For all characters that are not numbers or letters escape them by replacing with _<hex>_, where <hex> is the hexadecimal representation of the character.
  • In addition, if the first character is a number, escape it the same way. This is because variable names in Python can't start with a number. For example, 0app_2e_py is not a valid name, and so can't be used as part of an entrypoint, as in shiny.express.app:0app_2e_py.

In my testing, I found that uvicorn actually would accept other characters, like if you run:

uvicorn shiny.express.app:path/to/app.py

However, gunicorn would error if you run:

gunicorn shiny.express.app:path/to/app.py

because in gunicorn tries to parse the part after the : as an ast.Name or ast.Call, and path/to/app.py contains characters that are invalid for either of those types.

I decided to play it safe and make it general by escaping to valid Python variable names.

@wch wch merged commit d466195 into main Nov 18, 2023
@wch wch deleted the express-entrypoint branch November 18, 2023 04:50
@jcheng5
Copy link
Collaborator

jcheng5 commented Nov 18, 2023

This is impressively pragmatic 🎩

schloerke added a commit that referenced this pull request Nov 28, 2023
* main:
  Update shinylive to v0.1.1 (#825)
  Deploy dev docs on GitHub Pages (#824)
  Add docstrings
  Check for 'app' object in Express mode
  Use path to app as part of entrypoint for Express apps (#816)
  Install htmltools from github in CI (#811)
  Change htmltools dependency to use version number
  For layout.sidebar, default to open="always"
  Fix CSS class name
  Make page_sidebar main area white
  Update VS Code settings
  For quarto apps, check for `import *` (#810)
  Restore workaround for type stubs from typing_extensions
  Add try-except so parsing doesn't result in error
  Move is_express_app to separate file
  Add support for express mode apps (#767)
  Un-pin pyright version and fix type issues (#800)
  chore: Penguin app updates (#798)
  bug(`accordion(multiple=)`): Pass in accordion ID into accordion panel objects for `multiple` functionality (#799)
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