Skip to content

Add plotly run command #3329

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

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open

Add plotly run command #3329

wants to merge 6 commits into from

Conversation

T4rk1n
Copy link
Contributor

@T4rk1n T4rk1n commented Jun 9, 2025

Add a command to run dash app from the terminal.

The command can be run two methods:

  • plotly run app:app --debug
  • python -m dash run app:app --debug

The arguments follow Dash.run, run help:

$ plotly run --help
usage: plotly run [-h] [--host HOST] [--port PORT] [--proxy PROXY] [--debug | --no-debug | -d] [--dev-tools-ui | --no-dev-tools-ui] [--dev-tools-props-check | --no-dev-tools-props-check]
                  [--dev-tools-serve-dev-bundles | --no-dev-tools-serve-dev-bundles] [--dev-tools-hot-reload | --no-dev-tools-hot-reload] [--dev-tools-hot-reload-interval DEV_TOOLS_HOT_RELOAD_INTERVAL]
                  [--dev-tools-hot-reload-watch-interval DEV_TOOLS_HOT_RELOAD_WATCH_INTERVAL] [--dev-tools-hot-reload-max-retry DEV_TOOLS_HOT_RELOAD_MAX_RETRY]
                  [--dev-tools-silence-routes-logging | --no-dev-tools-silence-routes-logging] [--dev-tools-disable-version-check | --no-dev-tools-disable-version-check] [--dev-tools-prune-errors | --no-dev-tools-prune-errors]
                  app

Run a local development server for a Dash app.

positional arguments:
  app                   The Dash app to run, in the format "module:variable".

options:
  -h, --help            show this help message and exit
  --host HOST           Host IP used to serve the application (Default: "127.0.0.1").
  --port PORT, -p PORT  Port used to serve the application (Default: "8050").
  --proxy PROXY         Proxy configuration string, e.g., "http://0.0.0.0:8050::https://my.domain.com".
  --debug, --no-debug, -d
                        Enable/disable Flask debug mode and dev tools.

dev tools options:
  --dev-tools-ui, --no-dev-tools-ui
                        Enable/disable the dev tools UI.
  --dev-tools-props-check, --no-dev-tools-props-check
                        Enable/disable component prop validation.
  --dev-tools-serve-dev-bundles, --no-dev-tools-serve-dev-bundles
                        Enable/disable serving of dev bundles.
  --dev-tools-hot-reload, --no-dev-tools-hot-reload
                        Enable/disable hot reloading.
  --dev-tools-hot-reload-interval DEV_TOOLS_HOT_RELOAD_INTERVAL
                        Interval in seconds for hot reload polling (Default: 3).
  --dev-tools-hot-reload-watch-interval DEV_TOOLS_HOT_RELOAD_WATCH_INTERVAL
                        Interval in seconds for server-side file watch polling (Default: 0.5).
  --dev-tools-hot-reload-max-retry DEV_TOOLS_HOT_RELOAD_MAX_RETRY
                        Max number of failed hot reload requests before failing (Default: 8).
  --dev-tools-silence-routes-logging, --no-dev-tools-silence-routes-logging
                        Enable/disable silencing of Werkzeug's route logging.
  --dev-tools-disable-version-check, --no-dev-tools-disable-version-check
                        Enable/disable the Dash version upgrade check.
  --dev-tools-prune-errors, --no-dev-tools-prune-errors
                        Enable/disable pruning of tracebacks to user code only.

Copy link

@syl-oh syl-oh left a comment

Choose a reason for hiding this comment

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

Nice, that'll make remembering all the debug flags easier

Copy link

Choose a reason for hiding this comment

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

Do we want to use that in the CI for some test to avoid regression?

@emilykl
Copy link
Contributor

emilykl commented Jun 9, 2025

@T4rk1n What do you think about using app as the default variable name if no variable name is provided? So e.g. if you had a file named my_dash_app.py containing an app variable called app, you could just run

plotly run my_dash_app --debug

@emilykl
Copy link
Contributor

emilykl commented Jun 9, 2025

@T4rk1n For the flags, is there a way to make the helptext clearer to the user about which option is the default? I.e. if I can pass --debug or --no-debug, how do I know what is the default behavior if I pass neither?

For that matter (since I do know that no-debug is the default), what is the use case for the --no-debug flag?

@ndrezn
Copy link
Member

ndrezn commented Jun 9, 2025

We should be able to detect the app object automatically given a Python file. Here's a pattern to do this: https://github.com/plotly/de-client/blob/main/src/de_client/cli/root.py#L302-L306

@T4rk1n
Copy link
Contributor Author

T4rk1n commented Jun 9, 2025

@T4rk1n What do you think about using app as the default variable name if no variable name is provided? So e.g. if you had a file named my_dash_app.py containing an app variable called app, you could just run

plotly run app --debug

Yes that might be more convenient 👍

@T4rk1n For the flags, is there a way to make the helptext clearer to the user about which option is the default? I.e. if I can pass --debug or --no-debug, how do I know what is the default behavior if I pass neither?

For that matter (since I do know that no-debug is the default), what is the use case for the --no-debug flag?

Oh, the --no-<option> is added by argparse.BooleanOptionalAction, I didn't notice them before but they don't make much sense since those are flags, I'll see how to remove them.

:param app_path: The import path to the Dash app instance.
:return: The loaded Dash app instance.
"""
app_split = app_path.split(":")
Copy link
Contributor

Choose a reason for hiding this comment

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

check that len(app_split) == 2 here?

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, I see that further down you're allowing users to provide just the module name, then using the first Dash you find in that module.

app_instance = module_var
break

if not isinstance(app_instance, Dash):
Copy link
Contributor

Choose a reason for hiding this comment

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

if I run with just the module name, but the module doesn't define a Dash, I think app_instance will be uninitialized at the point of the isinstance() check.

@gvwilson gvwilson added feature something new P1 needed for current cycle labels Jun 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature something new P1 needed for current cycle
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants