run_app

run_app(
    app='app:app',
    host='127.0.0.1',
    port=8000,
    *,
    autoreload_port=0,
    reload=False,
    reload_dirs=None,
    reload_includes=RELOAD_INCLUDES_DEFAULT,
    reload_excludes=RELOAD_EXCLUDES_DEFAULT,
    ws_max_size=16777216,
    log_level=None,
    app_dir='.',
    factory=False,
    launch_browser=False,
    dev_mode=True,
    **kwargs,
)

Starts a Shiny app. Press Ctrl+C (or Ctrl+Break on Windows) to stop the app.

Parameters

app : str | shiny.App = 'app:app'

The app to run. The default, app:app, represents the “usual” case where the application is named app inside a app.py file within the current working directory. In other cases, the app location can be specified as a <module>:<attribute> string where the :<attribute> is only necessary if the application is named something other than app. Note that <module> can be a relative path to a .py file or a directory (with an app.py file inside of it); and in this case, the relative path is resolved relative to the app_dir directory.

host : str = '127.0.0.1'

The address that the app should listen on.

port : int = 8000

The port that the app should listen on. Set to 0 to use a random port.

autoreload_port : int = 0

The port that should be used for an additional websocket that is used to support hot-reload. Set to 0 to use a random port.

reload : bool = False

Enable auto-reload.

reload_dirs : Optional[list[str]] = None

A list of directories (in addition to the app directory) to watch for changes that will trigger an app reload.

reload_includes : list[str] | tuple[str, …] = RELOAD_INCLUDES_DEFAULT

List or tuple of file globs to indicate which files should be monitored for changes. Can be combined with reload_excludes.

reload_excludes : list[str] | tuple[str, …] = RELOAD_EXCLUDES_DEFAULT

List or tuple of file globs to indicate which files should be excluded from reload monitoring. Can be combined with reload_includes

ws_max_size : int = 16777216

WebSocket max size message in bytes.

log_level : Optional[str] = None

Log level.

app_dir : Optional[str] = '.'

The directory to look for app under (by adding this to the PYTHONPATH).

factory : bool = False

Treat app as an application factory, i.e. a () -> callable.

launch_browser : bool = False

Launch app browser after app starts, using the Python webbrowser module.

****kwargs** : object = {}

Additional keyword arguments which are passed to uvicorn.run. For more information see Uvicorn documentation.

Tip

The shiny run command-line interface (which comes installed with Shiny) provides the same functionality as shiny.run_app().

Examples

from shiny import run_app

# Run ``app`` inside ``./app.py``
run_app()

# Run ``app`` inside ``./myapp.py`` (or ``./myapp/app.py``)
run_app("myapp")

# Run ``my_app`` inside ``./myapp.py`` (or ``./myapp/app.py``)
run_app("myapp:my_app")

# Run ``my_app`` inside ``../myapp.py`` (or ``../myapp/app.py``)
run_app("myapp:my_app", app_dir="..")