diff --git a/CHANGELOG.md b/CHANGELOG.md index d3b77ae064..e0eed61f06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ This project adheres to [Semantic Versioning](https://semver.org/). ### Fixed - [#3916](https://github.com/plotly/dash/pull/3916) Fixed a regression where dragging multiple files into `dcc.Upload` would upload only the first file when `multiple=True` - [#3922](https://github.com/plotly/dash/pull/3922) Fix `dcc.Input(type="number")` stepper behavior when only `min` is set. +- [#3925](https://github.com/plotly/dash/pull/3925) Use the proxied url as the Jupyter server url so `DASH_PROXY` is honored by the external url and inline iframe in notebooks. ## [4.4.1] - 2026-07-21 diff --git a/dash/dash.py b/dash/dash.py index fd6a8d017d..134e92107f 100644 --- a/dash/dash.py +++ b/dash/dash.py @@ -2605,6 +2605,14 @@ def verify_url_part(served_part, url_part, part_name): extra_files.append(path) if jupyter_dash.active: + if jupyter_server_url is None and proxy: + # The app is served on host:port but reached through the proxy, + # so the notebook must display the proxied url. + proxied_url = urlparse(proxy.split("::")[1]) + jupyter_server_url = ( + f"{proxied_url.scheme}://{proxied_url.hostname}" + + (f":{proxied_url.port}" if proxied_url.port else "") + ) jupyter_dash.run_app( self, mode=jupyter_mode, diff --git a/tests/unit/test_configs.py b/tests/unit/test_configs.py index 461b8d7994..d3f1bbd088 100644 --- a/tests/unit/test_configs.py +++ b/tests/unit/test_configs.py @@ -5,6 +5,7 @@ from flask import Flask from dash import Dash, exceptions as _exc +from dash._jupyter import jupyter_dash # noinspection PyProtectedMember from dash._configs import ( @@ -379,6 +380,21 @@ def test_proxy_success(mocker, caplog, empty_environ, proxy, host, port, path): assert "Dash is running on {}{}\n".format(proxy, path) in caplog.text +def test_proxy_jupyter_server_url(mocker, empty_environ): + # The app is served on host:port but reached through the proxy, so the + # notebook must be given the proxied url. + proxy = "https://daash.plot.ly" + host, port = "127.0.0.1", 8050 + app = Dash() + mocker.patch.object(app.server, "run") + mocker.patch.object(type(jupyter_dash), "active", True) + run_app = mocker.patch.object(jupyter_dash, "run_app") + + app.run(proxy="http://{}:{}::{}".format(host, port, proxy), host=host, port=port) + + assert run_app.call_args.kwargs["server_url"] == proxy + + def test_proxy_failure(mocker, empty_environ): app = Dash()