简体   繁体   中英

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. The conversion step is performed by LibreOffice at the command line with:

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. Therefore, I resorted to launching an AWS EC2 Ubuntu instance and installed LibreOffice's latest version. Of course, I also installed Shiny Server so my app could be hosted on there. 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.

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. 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. I verified whether Shiny realizes that LibreOffice is installed on the server with:

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. The error message I get even when I try to determine LibreOffice's version from Shiny with

libreoffice --version

is

Executing 'libreoffice' failed with status 127

which means that the libreoffice command was not found according to my research. 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. I even verified the permissions on libreoffice from Shiny with

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?

My question, then, is: How do I get Shiny to use third party software installed on a server?

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.

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. The error I was getting was a "missing file", even when executed as from an R process launched as root .

/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. I could succesfully run libreoffice --version from Shiny when testing with this app:

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM