Unable to use third party software via command line from Shiny Server

Hi all,

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.

The shiny user can't login into your system so I guess it can't execute either even if the global permissions specify x, since it would be very dangerous allowing the shiny user to arbitrarily execute system commands from a web application.

Why don't you export the pdf file using rmarkdown? It would be way easier.

1 Like

@andresrcs The Excel files do not just contain tables. They contain all sorts of things. The renaming and converting have always been done manually and I would like to automate the process.

Any pointers regarding how I could allow the user to log in the system? Anything I should be looking into?

Thank you.

EDIT:

Upon rereading your post, you said "The shiny user can't login into your system...". Does it mean that it is completely impossible to do so?

I guess you can modify the shiny user to allow login and that should allow it to execute but I don't have any practical experience with that, as I said, is a big security risk and has no sensible application for shiny apps.

You could also execute the command as another user with sudo su - @otheruser but all of this is more Linux than shiny related so I think we are going off-topic here.

@andresrcs This is well noted. I appreciate the help. Thank you very much.

It turns out that the issue was on libreoffice's side. It requires the addition of an environment variable (source). So I added this line of code to my Shiny app code:

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

This trick was what I needed to get everything to work.

I greatly appreciate the help from @mikmart, who did a lot of work on another platform to help me out in this question.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.