Skip to content

Commit 1bbe729

Browse files
committed
Adds DASH and PORT env vars to run_server
1 parent aa20bd4 commit 1bbe729

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ All notable changes to `dash` will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

55
## [Unreleased]
6+
### Added
7+
- [#1134](https://github.com/plotly/dash/pull/1134) Allow `dash.run_server()` host and port parameters to be set with environment variables HOST & PORT, respectively
8+
69
### Changed
710
- [#1145](https://github.com/plotly/dash/pull/1145) Update from React 16.8.6 to 16.13.0
811

dash/dash.py

+18-3
Original file line numberDiff line numberDiff line change
@@ -1841,7 +1841,8 @@ def delete_resource(resources):
18411841

18421842
def run_server(
18431843
self,
1844-
port=8050,
1844+
host=os.getenv("HOST", "127.0.0.1"),
1845+
port=os.getenv("PORT", "8050"),
18451846
debug=False,
18461847
dev_tools_ui=None,
18471848
dev_tools_props_check=None,
@@ -1860,7 +1861,12 @@ def run_server(
18601861
If a parameter can be set by an environment variable, that is listed
18611862
too. Values provided here take precedence over environment variables.
18621863
1864+
:param host: Host IP used to serve the application
1865+
env: ``HOST``
1866+
:type host: string
1867+
18631868
:param port: Port used to serve the application
1869+
env: ``PORT``
18641870
:type port: int
18651871
18661872
:param debug: Set Flask debug mode and enable dev tools.
@@ -1933,9 +1939,18 @@ def run_server(
19331939
dev_tools_prune_errors,
19341940
)
19351941

1942+
# Verify port value
1943+
try:
1944+
port = int(port)
1945+
assert port in range(1, 65536)
1946+
except Exception as e:
1947+
e.args = [
1948+
"Expecting an integer from 1 to 65535, found port={}".format(repr(port))
1949+
]
1950+
raise
1951+
19361952
if self._dev_tools.silence_routes_logging:
19371953
# Since it's silenced, the address doesn't show anymore.
1938-
host = flask_run_options.get("host", "127.0.0.1")
19391954
ssl_context = flask_run_options.get("ssl_context")
19401955
self.logger.info(
19411956
"Running on %s://%s:%s%s",
@@ -1955,4 +1970,4 @@ def run_server(
19551970

19561971
self.logger.info("Debugger PIN: %s", debugger_pin)
19571972

1958-
self.server.run(port=port, debug=debug, **flask_run_options)
1973+
self.server.run(host=host, port=port, debug=debug, **flask_run_options)

0 commit comments

Comments
 (0)