[英]Write data to different directory for shiny-app
I have a shiny-app on linux running shiny-server. 我在运行Shiny-Server的Linux上有一个Shiny-app。 Following my setup the apps are located in
/srv/shiny-server/app-dir/
. 完成我的设置后,应用程序位于
/srv/shiny-server/app-dir/
。
I want to write a file to that directory for my shiny-app to read, using a .R
file that I put together. 我想使用放在一起的
.R
文件将文件写入该目录以供我的闪亮应用读取。 In that file I write the data like this: write.csv(df, "file.csv")
. 在该文件中,我这样写数据:
write.csv(df, "file.csv")
。 If I run this file from my shiny-app directory using Rscript /srv/shiny-server/app-dir/write_script.R
, it writes the data to /home/ec2-user
. 如果我使用
Rscript /srv/shiny-server/app-dir/write_script.R
从Rscript /srv/shiny-server/app-dir/write_script.R
-app目录运行此文件,它将把数据写入/home/ec2-user
。
If I change the write
command to write.csv(df, '/srv/shiny-server/app-dir/data.csv')
and run the same way it does not work (permission denied). 如果我将
write
命令更改为write.csv(df, '/srv/shiny-server/app-dir/data.csv')
并以不起作用的方式运行(权限被拒绝)。
Nor can I read files in /home/ec2-user/
from within my shiny-app. 我也无法从我的闪亮应用程序中读取
/home/ec2-user/
文件。
So my question is: how can I write files from an R script (not the server.R file in a shiny app) that can be accessed by my shiny-app, given my folder structure outlined above? 所以我的问题是:考虑到我上面概述的文件夹结构,我该如何从R脚本(不是闪亮的应用程序中的server.R文件)写入可以被我的闪亮应用程序访问的文件?
Shiny Apps are executed by user shiny
, which has no access to the home
-directory of the user ec2-user
. 闪亮的应用是由用户执行的
shiny
,其在没有接入home
用户的-directory ec2-user
。 You can change the reading permissions of the file just after copying it into /srv/shiny-server/app-dir
: 将文件复制到
/srv/shiny-server/app-dir
后,即可更改文件的读取权限:
chmod a+r /srv/shiny-server/app-dir/file.csv
chmod a+r /srv/shiny-server/app-dir/file.csv
system2("chmod", list("a+r", "/srv/shiny-server/app-dir/file.csv")
system2("chmod", list("a+r", "/srv/shiny-server/app-dir/file.csv")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.