Plotly dash in docker 不加载资产

Plotly dash in docker do not load assets

我有一个多页 dash 应用程序,当 运行 在本地使用时,它按预期工作:

waitress-serve --listen=0.0.0.0:80 web_app.wsgi:application

所以 assets 文件夹中的所有资产都正确加载,图像 ar 加载 src=app.get_asset_url('xyz.png') 并将 app.css.config.serve_locally 设置为 true,如此处所示,所有内容都加载 working

但是当在 docker 容器中加载同一个应用程序时,资产不会加载 not working 因此本地 css 也不会加载。

已检查 docker 中的文件和文件夹,一切都符合预期。

我想我在某处遗漏了一些东西,但没有找到什么,关于如何让它工作的任何建议?

Docker 文件

FROM python:3

RUN apt-get update && apt-get install -qq -y \
build-essential libpq-dev --no-install-recommends

ENV INSTALL_PATH /gtg_analytics-master
ENV PYTHONPATH "${PYTHONPATH}:$INSTALL_PATH/web_app"
RUN mkdir -p $INSTALL_PATH

WORKDIR $INSTALL_PATH

COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt

COPY web_app $INSTALL_PATH/web_app

docker-撰写:

version: "3"

services:
web_app:
image: patber/gtg:dev
build: .
command: >
  waitress-serve --listen=0.0.0.0:80
  web_app.wsgi:application
environment:
  PYTHONUNBUFFERED: 'true'
volumes:
  - '.:/web_app'
ports:
  - '80:80'

找到 CSS 个文件的解决方案 here

app.css.append_css({"external_url": "./assets/xyz.css"})

我运行遇到同样的问题,这里提供的解决方案是正确的,但您还需要添加:

app.css.config.serve_locally = False

此外,您可以通过以下方式添加样式表,而不是追加:

external_stylesheets=["./assets/stylesheet.css"]
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)

这不是很好,但如果您需要提供 css 以外的服务,您也可以使用外部资源选项:

app = dash.Dash(
    __name__,
    assets_external_path='http://your-external-assets-folder-url/'
)

我 运行 用图像进入这个,这是我知道的最好的(当前 = 20 年 1 月 30 日)解决方案。