plotly / orca

Command line application for generating static images of interactive plotly charts
MIT License
296 stars 39 forks source link

I get "Error in processx::run: System command error" when using orca inside Docker #211

Closed 0navarro closed 5 years ago

0navarro commented 5 years ago

I am using orca inside a downloadHandler function in an R-Shiny app inside Docker. When I click on the download button to generate and dowonload a plot I get disconnected from the session. Moreover, on the log file I get: Warning: Error in processx::run: System command error

I am using xvfb-run to run orca with a script like this: xvfb-run -a /squashfs-root/app/orca "$@"

Here is a minimal example of the shiny app:

library(shiny)
library(plotly)

ui <- fluidPage(   
         downloadButton('plot_download', 'Download plot')    
)
server <- function(input, output) {
  output$plot_download <- downloadHandler(
    filename = function(){
        plot_file_name<-'plot.png'
    },
    content = function(file) {

      path_split<-unlist(strsplit(file,'/'))

      download_path<-paste(path_split[1:length(path_split)-1],collapse='/')

      p <- plot_ly(x = 1:10, y = 1:10, color = 1:10)

      withr::with_dir(download_path, orca(p, path_split[length(path_split)]))

    })}
shinyApp(ui = ui, server = server)

Moreover, when I use orca in the R terminal inside Docker to generate the same plot, it works.

Here is my dockerfile:

# Install R version 3.5
FROM r-base:3.5.0

# Install Ubuntu packages
RUN apt-get update && apt-get install -y \
    sudo \
    gdebi-core \
    pandoc \
    pandoc-citeproc \
    libcurl4-gnutls-dev \
    libcairo2-dev/unstable \
    libxt-dev \
    libssl-dev \
    libpq-dev \
    libgtk2.0-bin \
    libx11-xcb1 \
    libxtst6 \
    libgconf-2-4 \
    libnss3 \
    libasound2 \
    xvfb

# Download and install ShinyServer (latest version)
RUN wget --no-verbose https://s3.amazonaws.com/rstudio-shiny-server-os-build/ubuntu-12.04/x86_64/VERSION -O "version.txt" && \
    VERSION=$(cat version.txt)  && \
    wget --no-verbose "https://s3.amazonaws.com/rstudio-shiny-server-os-build/ubuntu-12.04/x86_64/shiny-server-$VERSION-amd64.deb" -O ss-latest.deb && \
    gdebi -n ss-latest.deb && \
    rm -f version.txt ss-latest.deb

# Install R packages that are required
RUN R -e "install.packages(c('shiny', 'devtools', 'processx'), repos='http://cran.rstudio.com/')"

RUN R -e "devtools::install_github('ropensci/plotly')"

COPY orca_xvfb.sh /srv/shiny-server/orca_xvfb.sh
RUN chmod +x /srv/shiny-server/orca_xvfb.sh

# Download install orca (plotly library to download plots)
RUN wget --no-verbose -P /srv/shiny-server/ "https://github.com/plotly/orca/releases/download/v1.2.1/orca-1.2.1-x86_64.AppImage"
RUN chmod +x /srv/shiny-server/orca-1.2.1-x86_64.AppImage
RUN .//srv/shiny-server/orca-1.2.1-x86_64.AppImage --appimage-extract
RUN ln -s /srv/shiny-server/orca_xvfb.sh /usr/bin/orca
# Copy configuration files into the Docker image
COPY shiny-server.conf  /etc/shiny-server/shiny-server.conf
COPY /app /srv/shiny-server/

# Make the ShinyApp available at port 80
EXPOSE 80

# Copy further configuration files into the Docker image
COPY shiny-server.sh /usr/bin/shiny-server.sh

CMD ["/usr/bin/shiny-server.sh"]

I am using the github version of plotly. If I use the CRAN version and I try to download the plot, I get an error message saying that I need a mapbox token.

I really appreciate any help on this.

etpinard commented 5 years ago

https://github.com/ropensci/plotly/issues/1437#issuecomment-450675463

might help you and us debug.

0navarro commented 5 years ago

ropensci/plotly#1437 (comment)

might help you and us debug.

Hi etpinard, thanks for the reply.

When I run system("which orca") in the R terminal inside Docker I get:

/usr/bin/orca

When I run system("orca") I get:

Plotly's image-exporting utilities

  Usage: orca [--version] [--help] <command> [<args>]

  Available commands:
  - graph [or plotly-graph, plotly_graph]
    Generates an image of plotly graph from inputted plotly.js JSON attributes.
    For more info, run `orca graph --help`.
  - serve [or server]
    Boots up a server with one route per available export component
    For more info, run `orca serve --help`.

I added the flag debug=TRUE to my R-shiny app like this:

withr::with_dir(download_path, orca(p, path_split[length(path_split)], debug=TRUE) )

But I get the same error message in the log file as before:

Loading required package: ggplot2

Attaching package: ‘plotly’

The following object is masked from ‘package:ggplot2’:

    last_plot

The following object is masked from ‘package:stats’:

    filter

The following object is masked from ‘package:graphics’:

    layout

Listening on http://127.0.0.1:45137
Warning: Error in processx::run: System command error
  [No stack trace available]

So I am guessing that the log file is not capturing any debug messages from the orca function. Do you have any other idea of how could I further debug this?

0navarro commented 5 years ago

Moreover, after running the example with orca() in the R terminal inside Docker using the debug flag, I get a message like this:

>p <- plot_ly(x = 1:10, y = 1:10, color = 1:10)
>withr::with_dir('/var/log/', orca(p, 'plot.png', debug=TRUE))

No trace type specified:
  Based on info supplied, a 'scatter' trace seems appropriate.
  Read more about this trace type -> https://plot.ly/r/reference/#scatter
No scatter mode specifed:
  Setting the mode to markers
  Read more about this attribute -> https://plot.ly/r/reference/#scatter-mode
created index-31de0e3a-817c-4d4e-9a60-1a9e23b4ead6.html for plotly-graph component
gpu process crashed - false
          Chrome version 59.0.3071.115
          Electron version 1.8.4
gpu process crashed - false
          Chrome version 59.0.3071.115
          Electron version 1.8.4
exported plotx, in 437.799923 ms
-
  leaving window open for debugging
|
done with code 0 in 439.87 ms - all task(s) completed

I hope this helps clarify the issue.

etpinard commented 5 years ago

Thanks for all the info @0navarro !

Running orca with xvfb should be enough to solve the gpu process crashed issues:

https://github.com/plotly/orca#linux-troubleshooting-headless-server-configuration

0navarro commented 5 years ago

Thanks for all the info @0navarro !

Running orca with xvfb should be enough to solve the gpu process crashed issues:

https://github.com/plotly/orca#linux-troubleshooting-headless-server-configuration

I am already running orca with xvfb, using a shell script that runs the extracted orca AppImage. So, when I run cat /usr/bin/orca I get:

xvfb-run -a /squashfs-root/app/orca "$@"

etpinard commented 5 years ago

Ok. Have you tried to export a graph using orca in your docker container outside the R interface?

0navarro commented 5 years ago

Ok. Have you tried to export a graph using orca in your docker container outside the R interface?

I just ran an example. When I run: orca graph '{ "data": [{"y": [1,2,1]}] }' -o fig.png --debug=T

I get:

created index-43ff78e2-f9de-4a2d-a7b6-413e0889e22e.html for plotly-graph component
exported fig, in 756.871099 ms

  leaving window open for debugging

done with code 0 in 758.36 ms - all task(s) completed
antoinerg commented 5 years ago

@0navarro It seems like the command ran successfully: done with code 0 in 758.36 ms - all task(s) completed. Do you still have an issue?

0navarro commented 5 years ago

@0navarro It seems like the command ran successfully: done with code 0 in 758.36 ms - all task(s) completed. Do you still have an issue?

Hi antoinerg, thank you for your reply.

Unfortunately, I still have the issue. While the command above ran successfully, when I try to use orca within my shiny app within Docker, I get the error mentioned in my post.

When I run orca within Docker either with the R interface or with the terminal, it works fine. However, I get the error when I try to use orca within Docker within my shiny app.

Any insight on this is highly appreciated.

Diniodoc commented 5 years ago

Hi, I ran into a similar problem. In my case there was a problem with the input-filename in the orca function. The error occurs when you try to save the outputfile into a path which not exists. If there is a path in the filename, orca try to write into that, relatively to the current working directory.

I don't know your setup but are you sure that path_split[length(path_split)] is just the filename without any path? The right operator to give an absolute path is -d , which you can add via more_args.

orca(p,filename, more_args = c("-d",path_to_output ))

I tried your minimal example in a docker-container without problems.

Here my Dockerfile maybe it helps:

FROM openanalytics/r-base

# system libraries of general use
RUN apt-get update && apt-get install -y \
    sudo \
    pandoc \
    pandoc-citeproc \
    libcurl4-gnutls-dev \
    libcairo2-dev \
    libxt-dev \
    libssl-dev \
    libssh2-1-dev \
    libssl1.0.0

# system library dependency for the euler app
RUN apt-get update
RUN apt-get install -y libmpfr-dev

RUN R -e "install.packages('remotes', repos='https://cloud.r-project.org/')"

RUN R -e "remotes::install_github('ropensci/plotly')"

RUN R -e "remotes::install_github('rstudio/shiny',ref='v1.1.0')"

RUN R -e "install.packages(c('processx'), repos='https://cloud.r-project.org/')"

# install orca
RUN apt-get update -y
RUN apt-get install -y libudunits2-dev libproj-dev libgeos-dev libgdal-dev
RUN apt-get install -y libgtk2.0-0 libgconf-2-4 xvfb fuse desktop-file-utils

RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
RUN apt-get update -y
RUN apt-get install -y google-chrome-stable

RUN wget https://github.com/plotly/orca/releases/download/v1.2.1/orca-1.2.1-x86_64.AppImage -P /home
RUN chmod 777 /home/orca-1.2.1-x86_64.AppImage
RUN /home/orca-1.2.1-x86_64.AppImage --appimage-extract
RUN printf '#!/bin/bash \nxvfb-run --auto-servernum --server-args "-screen 0 640x480x24" /squashfs-root/app/orca "$@"' > /usr/bin/orca
RUN chmod 777 /usr/bin/orca

# copy the app to the image
RUN mkdir /root/shiny
COPY app.R /root/shiny

EXPOSE 3838

CMD ["R", "-e", "shiny::runApp('/root/shiny',port=3838, host = '0.0.0.0')"]
0navarro commented 5 years ago

Hi Diniodoc, thank you for you reply.

path_split[length(path_split)] does contain only the filename, withouth any path. Moreover, I tried using the -d operator but I got the same error. I used the operator as follows:

orca(p, path_split[length(path_split)], more_args=c("-d",download_path))

so path_split[length(path_split)] would contain the filename part of the file argument, such as filec0d15f01af0.png and download_path would contain the path part given by the file argument, such as /tmp/RtmpIGPXku.

This works well in RStudio outside docker, but throws the error when using Docker.

I will try your Dockerfile to see if this helps and I´ll post my results.

afrachioni commented 5 years ago

Hello! I'm having a similar issue on a headless Ubuntu machine where I'm trying to set up orca to make plotly figures offline:

$ xvfb-run -a orca graph --verbose test_fig.json 
Fontconfig warning: "/etc/fonts/fonts.conf", line 100: unknown element "blank"
gpu process crashed - false
          Chrome version 73.0.3683.121
          Electron version 5.0.1

The process just hangs there after printing this message. orca --version is 1.2.1. Happy to provide any additional information.

0navarro commented 5 years ago

Hello, I finally figured it out.

The problem was that the default user that runs the shiny app from the server, shiny, did not have access to the files in /squashfs-root/app/orca. At first I didn´t notice this because the message in the log file does not give any clue about permissions.

Anyway, I fixed the issue by running chown shiny:shiny -R /squashfs-root/ . I hope this helps.