使用shinyproxy部署闪亮的应用程序时,将其放置在哪里?

发布于 2025-02-10 01:10:40 字数 868 浏览 2 评论 0原文

我正在学习如何使用 shinyproxy 部署r Shiny应用程序.renviron包含用于访问数据库的全局变量的文件。

docker映像构建没有任何错误,但是当我使用容器启动容器时:

docker run -it -p 3838:3838 shinyproxy-template .

它在.renviron文件中找不到ENV变量,我最终会在R代码的一部分中遇到一个错误需要全球变量。

我当前的文件夹结构如下:

shinyproxy-template/
                   |- app-folder/
                   |- .gitignore
                   |- Dockerfile
                   |- README.md
                   |- app.Rproj
                   |- Rprofile.site
                   |- .Renviron

我尝试将.renviron文件放入app-folder/之内,然后再次构建了docker映像,但全局变量仍然无法访问。

我应该在哪里放置.renviron,以便应用程序访问全局变量?

I'm learning how to use shinyproxy to deploy R shiny applications but I can't figure out where to place my .Renviron file which contains global variables used to access a database.

The docker image builds without any errors but when I start the container using:

docker run -it -p 3838:3838 shinyproxy-template .

It doesn't find the env variables in the .Renviron file and I end up getting an error on the part of the R code that requires the global variables.

My current folder structure is as follows:

shinyproxy-template/
                   |- app-folder/
                   |- .gitignore
                   |- Dockerfile
                   |- README.md
                   |- app.Rproj
                   |- Rprofile.site
                   |- .Renviron

I tried placing the .Renviron file inside the app-folder/ then built the docker image again but the global variables were still inaccessible.

Where should I place the .Renviron so that the global variables are accessed by the app?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

栩栩如生 2025-02-17 01:10:40

有多个选项:

put .renviron文件到容器内的预期位置,

您可以将复制命令添加到dockerfile以复制您的<代码>。对于root用户,将是:

COPY .Renviron /root/

将环境变量从.renviron添加到dockerfile

添加行,例如:

ENV VAR1="value1"
ENV VAR2="value2"

到您的dockerfile

添加来自的环境变量。 /代码>到shinyproxy配置,

您可以通过使用

container-env:
  VAR1: VALUE1
  VAR2: VALUE2

container-env-file: /path/to/.Renviron

用于应用程序规范来定义application.yaml配置文件中的环境变量。请注意,这里的路径在主机上,而不是在容器内部。

对于Docker Run

进行Docker Run在Shinyproxy之外,您可以使用参数- env-file,其中诸如:

docker run -it -p 3838:3838 shinyproxy-template --env-file /path/to/shinyproxy-template/.Renviron

Releant文档链接:

There are multiple options:

Put .Renviron file to the expected location inside the container

You can add a COPY command to the Dockerfile to copy your .Renviron file to the expected location - i.e. either a home directory of the user or the WORKDIR location if defined in the Dockerfile. In case of the root user it would be:

COPY .Renviron /root/

Add environment variables from .Renviron to the Dockerfile

Add lines like:

ENV VAR1="value1"
ENV VAR2="value2"

to your Dockerfile

Add environment variables from .Renviron to the shinyproxy configuration

You can define environment variables in the application.yaml configuration file by either using

container-env:
  VAR1: VALUE1
  VAR2: VALUE2

or

container-env-file: /path/to/.Renviron

for your app specification. Note that the path here is on the host and not inside the container.

For docker run

When you do a docker run outside of shinyproxy you can use argument --env-file with something like:

docker run -it -p 3838:3838 shinyproxy-template --env-file /path/to/shinyproxy-template/.Renviron

Releant documentation links:

优雅的叶子 2025-02-17 01:10:40

编辑:请查看 @Max的解决方案。我们几乎在同一时间发布,但他的指示更清晰。


经过大量的反复试验,我终于得到了解决方案。


首先,启动Shinyproxy外部的容器以检查闪亮的应用程序是否正常运行?使用Docker的- env-file标志来指定.renviron filepath。在我的情况下,由于dockerfile.renviron都在同一文件夹中,因此我要做:

docker run -it --env-file .Renviron -p 3838:3838 shinyproxy-template .

该应用程序现在将识别文件,没有错误!


然后,我更改为目录,其中有shinyproxy-2.6.1.jar文件,然后使用java -jar-jar shinyproxy-2.6.6.1.jar再次运行它。当我试图启动我的ShinyApp时,有一个错误。它找不到env var。

因此,我求助于将它们直接添加到application.ymlshinyproxy-2.6.6.1.jar

  - id: app-folder
    display-name: My App
    description: My App's title
    container-cmd: ["R", "-e", "shiny::runApp('/root/app-folder')"]
    container-image: openanalytics/shinyproxy-template
    container-env:
        ENV1: ENV1-VALUE
        ENV2: ENV2-VALUE
        ENV3: ENV3-VALUE
    access-groups: scientists

的 位置相同的位置根据您的情况,相应的人在您身边。 Env Vars也是如此。


实际上,让我只提供整个application.yml文件的原型,请查看我添加的最后一个应用程序:

proxy:
  title: Open Analytics Shiny Proxy
  logo-url: https://www.openanalytics.eu/shinyproxy/logo.png
  landing-page: /
  # hide nav bar:
  hide-navbar: true
  heartbeat-rate: 10000
  heartbeat-timeout: 60000
  port: 8080
  authentication: ldap
  admin-groups: scientists
  # Example: 'simple' authentication configuration
  users:
  - name: jack
    password: password
    groups: scientists
  - name: jeff
    password: password
    groups: mathematicians
  # Example: 'ldap' authentication configuration
  ldap:
    url: ldap://ldap.forumsys.com:389/dc=example,dc=com
    user-dn-pattern: uid={0}
    group-search-base:
    group-search-filter: (uniqueMember={0})
    manager-dn: cn=read-only-admin,dc=example,dc=com
    manager-password: password
    # Docker configuration
  docker:
    url: http://localhost:2375
    port-range-start: 20000
  specs:
  - id: 01_hello
    display-name: Hello Application
    description: Application which demonstrates the basics of a Shiny app
    container-cmd: ["R", "-e", "shinyproxy::run_01_hello()"]
    container-image: openanalytics/shinyproxy-demo
    access-groups: [scientists, mathematicians]
  - id: 06_tabsets
    container-cmd: ["R", "-e", "shinyproxy::run_06_tabsets()"]
    container-image: openanalytics/shinyproxy-demo
    access-groups: scientists
  - id: euler
    display-name: Euler's number
    description: Adding another app to shinyproxy
    container-cmd: ["R", "-e", "shiny::runApp('/root/euler')"]
    container-image: openanalytics/shinyproxy-template
    access-groups: scientists
  - id: wca
    display-name: Wasanii
    description: WhatsApp Chat Analysis
    container-cmd: ["R", "-e", "shiny::runApp('/root/wca')"]
    container-image: wca
    container-env:
        FIREBASE_API_KEY: myfirebaseapikey
        FIREBASE_PROJECT_ID: myfirebaseprojectid
        FIREBASE_AUTH_DOMAIN: myfirebaseauthdomain
        FIREBASE_STORAGE_BUCKET: myfirebasestoragebucket
        FIREBASE_APP_ID: myfirebaseappid
        FIREBASE_DATABASE_URL: myfirebasedatabaseurl
    access-groups: scientists

logging:
  file:
    shinyproxy.log


显然有一个更好的解决方案可以参考renvionr直接文件,但由于我无法弄清楚这将会。

Edit: Have a look at @Max's solution. We posted at nearly the same time but his instructions are clearer.


After lots of trial and error I finally got a solution.


First, starting the container outside shinyproxy to check if the shiny app runs normally? Use docker's --env-file flag to specify the .Renviron filepath. In my case since both the Dockerfile and .Renviron are in the same folder so I'd do:

docker run -it --env-file .Renviron -p 3838:3838 shinyproxy-template .

The app will now recognize env vars defined in the .Renviron file and no errors!


I then changed into the directory where I had shinyproxy-2.6.1.jar file and ran it again using java -jar shinyproxy-2.6.1.jar. There was an error when I tried to start my shinyapp. It couldn't find the env vars.

So I resorted to adding them directly in the application.yml which is in the same location as shinyproxy-2.6.1.jar:

  - id: app-folder
    display-name: My App
    description: My App's title
    container-cmd: ["R", "-e", "shiny::runApp('/root/app-folder')"]
    container-image: openanalytics/shinyproxy-template
    container-env:
        ENV1: ENV1-VALUE
        ENV2: ENV2-VALUE
        ENV3: ENV3-VALUE
    access-groups: scientists

Replace the necessary parts of the yml section with the corresponding one's on your side depending on your case. The same applies to the env vars.


In fact let me just provide a prototype of my whole application.yml file, have a look at the last app I added "wca":

proxy:
  title: Open Analytics Shiny Proxy
  logo-url: https://www.openanalytics.eu/shinyproxy/logo.png
  landing-page: /
  # hide nav bar:
  hide-navbar: true
  heartbeat-rate: 10000
  heartbeat-timeout: 60000
  port: 8080
  authentication: ldap
  admin-groups: scientists
  # Example: 'simple' authentication configuration
  users:
  - name: jack
    password: password
    groups: scientists
  - name: jeff
    password: password
    groups: mathematicians
  # Example: 'ldap' authentication configuration
  ldap:
    url: ldap://ldap.forumsys.com:389/dc=example,dc=com
    user-dn-pattern: uid={0}
    group-search-base:
    group-search-filter: (uniqueMember={0})
    manager-dn: cn=read-only-admin,dc=example,dc=com
    manager-password: password
    # Docker configuration
  docker:
    url: http://localhost:2375
    port-range-start: 20000
  specs:
  - id: 01_hello
    display-name: Hello Application
    description: Application which demonstrates the basics of a Shiny app
    container-cmd: ["R", "-e", "shinyproxy::run_01_hello()"]
    container-image: openanalytics/shinyproxy-demo
    access-groups: [scientists, mathematicians]
  - id: 06_tabsets
    container-cmd: ["R", "-e", "shinyproxy::run_06_tabsets()"]
    container-image: openanalytics/shinyproxy-demo
    access-groups: scientists
  - id: euler
    display-name: Euler's number
    description: Adding another app to shinyproxy
    container-cmd: ["R", "-e", "shiny::runApp('/root/euler')"]
    container-image: openanalytics/shinyproxy-template
    access-groups: scientists
  - id: wca
    display-name: Wasanii
    description: WhatsApp Chat Analysis
    container-cmd: ["R", "-e", "shiny::runApp('/root/wca')"]
    container-image: wca
    container-env:
        FIREBASE_API_KEY: myfirebaseapikey
        FIREBASE_PROJECT_ID: myfirebaseprojectid
        FIREBASE_AUTH_DOMAIN: myfirebaseauthdomain
        FIREBASE_STORAGE_BUCKET: myfirebasestoragebucket
        FIREBASE_APP_ID: myfirebaseappid
        FIREBASE_DATABASE_URL: myfirebasedatabaseurl
    access-groups: scientists

logging:
  file:
    shinyproxy.log


There's obviously a better solution to refer to the .Renviron file directly but since I can't figure it out this will do.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文