使用shinyproxy部署闪亮的应用程序时,将其放置在哪里?
我正在学习如何使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有多个选项:
put
.renviron
文件到容器内的预期位置,您可以将
复制
命令添加到dockerfile
以复制您的<代码>。对于root用户,将是:将环境变量从
.renviron
添加到dockerfile添加行,例如:
到您的
dockerfile
添加来自
的环境变量。 /代码>到shinyproxy配置,
您可以通过使用
或
用于应用程序规范来定义
application.yaml
配置文件中的环境变量。请注意,这里的路径在主机上,而不是在容器内部。对于
Docker Run
进行
Docker Run
在Shinyproxy之外,您可以使用参数- env-file
,其中诸如:Releant文档链接:
There are multiple options:
Put
.Renviron
file to the expected location inside the containerYou can add a
COPY
command to theDockerfile
to copy your.Renviron
file to the expected location - i.e. either a home directory of the user or theWORKDIR
location if defined in the Dockerfile. In case of the root user it would be:Add environment variables from
.Renviron
to the DockerfileAdd lines like:
to your
Dockerfile
Add environment variables from
.Renviron
to the shinyproxy configurationYou can define environment variables in the
application.yaml
configuration file by either usingor
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:Releant documentation links:
编辑:请查看 @Max的解决方案。我们几乎在同一时间发布,但他的指示更清晰。
经过大量的反复试验,我终于得到了解决方案。
首先,启动Shinyproxy外部的容器以检查闪亮的应用程序是否正常运行?使用Docker的
- env-file
标志来指定.renviron
filepath。在我的情况下,由于dockerfile
和.renviron
都在同一文件夹中,因此我要做:该应用程序现在将识别
。
文件,没有错误!然后,我更改为目录,其中有
shinyproxy-2.6.1.jar
文件,然后使用java -jar-jar shinyproxy-2.6.6.1.jar
再次运行它。当我试图启动我的ShinyApp时,有一个错误。它找不到env var。因此,我求助于将它们直接添加到
application.yml
与shinyproxy-2.6.6.1.jar
中的 位置相同的位置根据您的情况,相应的人在您身边。 Env Vars也是如此。
实际上,让我只提供整个
application.yml
文件的原型,请查看我添加的最后一个应用程序:显然有一个更好的解决方案可以参考
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 theDockerfile
and.Renviron
are in the same folder so I'd do: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 usingjava -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 asshinyproxy-2.6.1.jar
: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":There's obviously a better solution to refer to the
.Renviron
file directly but since I can't figure it out this will do.