简体   繁体   English

无法通过命令行从托管在 AWS EC2 上的 Shiny 应用启动第三方软件

[英]Unable to launch third party software via command line from Shiny app hosted on AWS EC2

I am in the process of creating a Shiny app, which reads in Excel files, renames them and then converts them into PDF files.我正在创建一个 Shiny 应用程序,它读取 Excel 个文件,重命名它们,然后将它们转换为 PDF 个文件。 The conversion step is performed by LibreOffice at the command line with:转换步骤由 LibreOffice 在命令行中执行:

libreoffice --convert-to pdf myfile.xlsx

Since I needed LibreOffice as an external dependency for my project, I could not use shinyapps.io since there is no straightforward way to install LibreOffice on there.因为我需要 LibreOffice 作为我项目的外部依赖项,所以我无法使用 shinyapps.io,因为没有直接的方法可以在那里安装 LibreOffice。 Therefore, I resorted to launching an AWS EC2 Ubuntu instance and installed LibreOffice's latest version.因此,我启动了一个 AWS EC2 Ubuntu 实例并安装了 LibreOffice 的最新版本。 Of course, I also installed Shiny Server so my app could be hosted on there.当然,我还安装了 Shiny 服务器,所以我的应用程序可以托管在那里。 I need to mention that I am a beginner at using Shiny server on an AWS EC2 instance and using the Unix command line overall.我需要指出的是,我是在 AWS EC2 实例上使用 Shiny 服务器并总体上使用 Unix 命令行的初学者。

Now, here is my issue.现在,这是我的问题。 When I connect to the server via ssh and use LibreOffice to convert some Excel files to PDF, it works perfectly.当我通过 ssh 连接到服务器并使用 LibreOffice 将一些 Excel 文件转换为 PDF 时,它工作得很好。 However, when I try to access LibreOffice via the launched Shiny app via command line functions, it seems that the app does not have access to the software.但是,当我尝试通过启动的 Shiny 应用程序通过命令行功能访问 LibreOffice 时,该应用程序似乎无法访问该软件。 I verified whether Shiny realizes that LibreOffice is installed on the server with:我验证了 Shiny 是否意识到 LibreOffice 安装在服务器上:

which libreoffice

and it does since the response is它确实如此,因为响应是

/usr/bin/libreoffice

But it appears as though Shiny is unable to use it for some reason.但似乎 Shiny 出于某种原因无法使用它。 The error message I get even when I try to determine LibreOffice's version from Shiny with即使我尝试从 Shiny 确定 LibreOffice 的版本时也会收到错误消息

libreoffice --version

is

Executing 'libreoffice' failed with status 127

which means that the libreoffice command was not found according to my research.这意味着根据我的研究没有找到libreoffice命令。 Once again, when I'm on the server using the command line, everything works perfectly.再一次,当我在服务器上使用命令行时,一切正常。

It baffles me how Shiny knows that the software is installed, but cannot use it.百思不得其解,Shiny怎么知道安装了软件,却不能使用。 I even verified the permissions on libreoffice from Shiny with我什至从 Shiny 验证了libreoffice的权限

ls -l -H /usr/bin/libreoffice

and obtained并获得

-rwxr-xr-x 1 root root 6731 Mar  1 08:39 /usr/bin/libreoffice

I am no expert in Unix/Linux, but I think that this means that all users have access to it?我不是 Unix/Linux 专家,但我认为这意味着所有用户都可以访问它?

My question, then, is: How do I get Shiny to use third party software installed on a server?那么我的问题是:如何让 Shiny 使用安装在服务器上的第三方软件?

It may also be important to mention that I use the wonderful sys package by Jeroen Ooms for all my command line needs instead of using system2() in base R.值得一提的是,我使用Jeroen Ooms 的精彩 sys package 来满足我所有的命令行需求,而不是在 base R 中使用system2()

Thank you all in advance for your help.预先感谢大家的帮助。

I tested this in a Docker container, which may or may not lead to the same error.我在 Docker 容器中对此进行了测试,这可能会或可能不会导致相同的错误。 The error I was getting was a "missing file", even when executed as from an R process launched as root .我得到的错误是一个“丢失的文件”,即使从作为root启动的 R 进程执行时也是如此。

/usr/lib/libreoffice/program/soffice.bin: error while loading shared libraries: libreglo.so: cannot open shared object file: No such file or directory

Following this advice and setting the LD_LIBRARY_PATH environment variable fixed the issue in my testing.遵循此建议并设置LD_LIBRARY_PATH环境变量解决了我测试中的问题。 I could succesfully run libreoffice --version from Shiny when testing with this app:使用此应用程序进行测试时,我可以从 Shiny 成功运行libreoffice --version

library(shiny)

Sys.setenv(
  LD_LIBRARY_PATH = "/usr/lib/libreoffice/program:$LD_LIBRARY_PATH"
)

ui <- fluidPage(
  textInput("command", "Enter a command"),
  submitButton("Submit"),
  verbatimTextOutput("output"),
)

server <- function(input, output, session) {
  output$output <- renderPrint({
    system(input$command, intern = TRUE)
  })
}

shinyApp(ui, server, options = list(host = "0.0.0.0", port = 8080))

And, for completeness, the Dockerfile I tested with:而且,为了完整起见,我测试了Dockerfile

FROM rocker/shiny

RUN apt-get update && apt-get install -y \
  libreoffice-common

COPY . .

CMD ["Rscript", "app.R"]

And command to run the image:并命令运行图像:

docker run --user shiny --rm -it -p 8080:8080 shiny-libre

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我的 flask 应用程序正在从第三方 API 获取数据,同时在 EC2 上部署此应用程序时,它被挂起 - My flask app is fetching data from third party API , while deploying this app on EC2 , its getting hanged 如何更改权限:EC2 AWS 上的权限被拒绝 Shiny 应用程序 - How to Change Permissions: Permission Denied Shiny app on EC2 AWS AWS EC2,命令行显示实例类型 - AWS EC2, command line display instance type 无法访问 Owin 自托管 RestApi - 部署到 AWS EC2 - Windows 2012 R2 - Unable to Access Owin Self hosted RestApi - Deployed to AWS EC2 - Windows 2012 R2 AWS EC2 无法访问 EKS - AWS EC2 unable to access EKS 如何使用命令行检查 aws ec2 实例创建日期? - How to check the aws ec2 instance creation date using command line? 通过 Bitbucket 管道从 AWS S3 部署到 AWS EC2 - Deploy to AWS EC2 from AWS S3 via Bitbucket Pipelines 从 EC2 到 AWS 服务(如 dynamodb)的连接是在 AWS 网络内发生的,还是通过公共 inte.net 发生的? - Is the connection from EC2 to AWS Service (like dynamodb) happening within the AWS Network, or via public internet? AWS EC2 阻止来自外部请求的 Tomcat Web 应用程序 - AWS EC2 Blocking Tomcat Web App from Outside Requests 为 AWS ec2 机器上托管的 API 实施 HTTPS 的最佳方法 - Best way to implement HTTPS for API hosted on AWS ec2 machine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM