在 ShinyProxy 中获取 CSS 和 Javascript 文件时如何修复“404(未找到)”错误

How to fix '404 (Not Found)' errors when sourcing CSS and Javascript files in ShinyProxy

我正在尝试使用 ShinyProxy 启动一个闪亮的应用程序 - 我以前做过很多次。但是,此应用程序未正确使用使其成为 运行.

所需的任何 CSS 或 JS 文件

当我 运行 使用 docker run -p 3838:3838 my_app 手动应用程序时,一切正常。但是,当将 ShinyProxy 指向 my_app 图像时,生成的应用程序无法加载任何 CSS 或 JS 文件。

Dockerfile

FROM openanalytics/r-base

MAINTAINER Daniel Beachnau "DannyBeachnau@gmail.com"

# Dependencies outside of R
RUN apt-get update && apt-get install -y \
    sudo \
    gdebi-core \
    pandoc \
    pandoc-citeproc \
    libcurl4-gnutls-dev \
    libcairo2-dev \
    libxt-dev \
    xtail \
    wget \
    libpq-dev \
    libmariadb-client-lgpl-dev \
    # Might be needed for the archivist R-Library
    dbus \
    systemd \
    # needed for odbc
    unixodbc-dev

RUN apt-get install apt-transport-https curl -y
RUN curl http://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN apt-get update
RUN ACCEPT_EULA=Y apt-get install msodbcsql17 -y

# Download R-Packages
# tidyverse
RUN R -e "install.packages('tidyr')"
RUN R -e "install.packages('dplyr')"
RUN R -e "install.packages('readr')"
# Shiny Packages
RUN R -e "install.packages('shiny')"
RUN R -e "install.packages('shinycssloaders')"
RUN R -e "install.packages('shinydashboard')"
RUN R -e "install.packages('shinyWidgets')"
RUN R -e "install.packages('DT')"
RUN R -e "install.packages('shinyjs')"
RUN R -e "install.packages('flexdashboard')"
# Database Packages
RUN R -e "install.packages('odbc')"
RUN R -e "install.packages('RMySQL')"
# Other
RUN R -e "install.packages('devtools')"
RUN R -e "install.packages('lubridate')"
RUN R -e "install.packages('reshape2')"
RUN R -e "install.packages('grid')"
RUN R -e "install.packages('lemon')"
RUN R -e "install.packages('scales')"
RUN R -e "install.packages('ggthemes')"
RUN R -e "install.packages('ggplot2')"

RUN R -e "devtools::install_bitbucket(repo = 'my_repo/my_package',  auth_user = 'my_username', password = 'my_password')"

# copy the app to the image
COPY . /root

# run the script to update the app data
WORKDIR /root
RUN Rscript app_data_update.R

WORKDIR /root/app
COPY Rprofile.site /usr/lib/R/etc/
EXPOSE 3838
CMD ["R", "-e", "shiny::runApp('/root/app', host='0.0.0.0', port=3838)"]

application.yml

shiny:
  proxy:
    title: ShinyProxy Server
    logo-url: /images/logo-image.png
    landing-page: /
    heartbeat-rate: 10000
    heartbeat-timeout: 60000
    container-wait-time: 60000
    port: 8080
    authentication: ldap

    # Docker configuration
    docker:
      cert-path: /home/none
      url: http://localhost:2375
      port-range-start: 20000
    support:
      container-log-path: ./container-logs
      mail-to-address: DannyBeachnau@gmail.co,

  - name: my_apps_name
    display-name: Shiny App
    docker-image: dbeachnau/my_app
    groups: [Shiny Users Management]
    logo-url: /images/logo-image.png
    container-volumes: ["/path/to/app:/root/app"]


logging:
  file:
    shinyproxy.log

以下是应用在闪亮代理中的样子。

problem

这是手动 运行ning 时我的应用程序的外观。

desired

chrome 的检查工具中的控制台充满了诸如

之类的错误

GET https://myshinyserver.com/container_name/font-awesome-5.3.1/css/all.min.css net::ERR_ABORTED 404 (Not Found)

我在 ShinyProxy 上确实有其他应用程序 运行ning 可以正常显示,但我无法解决这些应用程序的配置方式与此应用程序的配置方式之间的差异。让我知道是否需要其他详细信息来诊断问题。感谢所有反馈 - 谢谢。

您必须在 Dockerfile 的顶部安装请求的字体。您可以将其添加到列表中 "Dependencies outside of R":

sudo apt-get install fonts-font-awesome

我已经解决了我的问题,但是,这仍然不能算是一个充分的答案或解释,因为我无法解释为什么这个解决方案会有所不同。我决定使用现在可用的不同基础映像重写 Dockerfile。我的代码中没有其他任何变化 - 只是 Dockerfile。工作 docker 文件如下:

FROM rocker/shiny-verse
# based on debian 9

MAINTAINER Daniel Beachnau "DannyBeachnau@gmail.com"

# Dependencies outside of R
RUN apt-get update && apt-get install -y \
    gnupg2 \
    apt-utils \
    sudo \
    gdebi-core \
    libxt-dev \
    xtail \
    wget

# Install ODBC driver from microsoft
RUN apt-get install apt-transport-https curl -y
RUN curl http://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/debian/9/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN apt-get update
RUN ACCEPT_EULA=Y apt-get install msodbcsql17 -y

# Download R-Packages
# Shiny Packages
RUN R -e "install.packages('shinycssloaders')"
RUN R -e "install.packages('shinydashboard')"
RUN R -e "install.packages('shinyWidgets')"
RUN R -e "install.packages('DT')"
RUN R -e "install.packages('shinyjs')"
RUN R -e "install.packages('flexdashboard')"
# Database Packages
RUN R -e "install.packages('odbc')"
RUN R -e "install.packages('RMySQL')"
# Other
RUN R -e "install.packages('lubridate')"
RUN R -e "install.packages('reshape2')"
RUN R -e "install.packages('scales')"
RUN R -e "install.packages('ggthemes')"
RUN R -e "install.packages('ggplot2')"

RUN R -e "devtools::install_bitbucket(repo = 'my_repo',  auth_user = 'my_username', password = 'my_password')"

# copy the app to the image
COPY . /root

# run the script to update the app data
WORKDIR /root
RUN Rscript app_data_update.R

WORKDIR /root/app
COPY Rprofile.site /usr/lib/R/etc/
EXPOSE 3838
CMD ["R", "-e", "shiny::runApp('/root/app', host='0.0.0.0', port=3838)"]

如果有人知道为什么观察到这种行为,我很乐意听到它,因为至少可以说我感到困惑。

您可能会在 Shiny v1.3.0 中看到这一点,而在早期版本中则看不到。如果是这样,可能是因为您的 NGINX 代理指令配置错误。我已经写下了详细信息 here,但我还会 post 此处列出重要的详细信息。

proxy_set_header Connection "upgrade";

此指令导致 NGINX 添加一个连接:升级 header 到每个 HTTP 请求,而它应该只用于 WebSockets。

这一行是 NGINX Inc. 自己推荐的,但是,这些建议旨在代理仅 WebSockets 的流量,而 Shiny 流量是普通 HTTP 请求和 WebSockets 的组合。 shiny/httpuv旧版本不介意这种情况,但新版本更严格。

正确的配置如下所示:

http {

  map $http_upgrade $connection_upgrade {
      default upgrade;
      ''      close;
    }

  server {
    listen 80;


    location / {
      proxy_pass http://localhost:3838;
      proxy_redirect / $scheme://$http_host/;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection $connection_upgrade;
      proxy_read_timeout 20d;
      proxy_buffering off;
    }
  }
}

有关其他示例,请参阅 RStudio Community post 中链接的文章。

why this solution makes a difference

这似乎是 Shiny 版本的问题,更改基本图像很可能已经解决了这个问题。

Shiny apps not rendering after updated to v1.3.0