在 Shiny Server 上找不到 PhantomJS

PhantomJS not found on Shiny Server

我正在使用 plotly 的导出功能生成 png 图。 我在 Ubuntu 14.04.

上安装了 Shiny Server

它适用于我的本地计算机。 当我从服务器上的控制台打开 R 时,它会起作用。但是,当我 运行 服务器上的 Shiny 应用程序时,出现 PhantomJS 错误。

PhantomJS not found. You can install it with webshot::install_phantomjs(). If it is installed, please make sure the phantomjs executable can be found via the PATH variable.

我已经安装了 PhantomJS,因为我可以通过 R 控制台生成图像,我认为它存在于 PATH 中。

如何解决这个问题或如何测试以找到问题点?

首先,从 Ubuntu 服务器上的终端安装 webshot 软件包:

sudo su - -c "R -e \"install.packages('webshot')\""

接下来,按照phantomJSinstallation description

sudo apt-get update
sudo apt-get install build-essential chrpath libssl-dev libxft-dev -y
sudo apt-get install libfreetype6 libfreetype6-dev -y
sudo apt-get install libfontconfig1 libfontconfig1-dev -y
cd ~
export PHANTOM_JS="phantomjs-2.1.1-linux-x86_64"
wget https://github.com/Medium/phantomjs/releases/download/v2.1.1/$PHANTOM_JS.tar.bz2
sudo tar xvjf $PHANTOM_JS.tar.bz2
sudo mv $PHANTOM_JS /usr/local/share
sudo ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/local/bin
phantomjs --version

有了这个,您应该可以在 Shiny App 中使用 webshotphantomJS

我已经用我添加到 /srv/shiny-server/:

的小样本测试应用程序对其进行了测试

ui.R 看起来像这样:

library(shiny)

ui <- fluidPage(

  # App title ----
  titlePanel("Test App to display webshot"),

  # Sidebar layout
  sidebarLayout(


    sidebarPanel(

      #actually useless part

    ),

    # Main panel for displaying outputs ----
    mainPanel(

      # Output: screenshot ----
      imageOutput("webshot_image")

    )
  )
)

server.R 看起来像这样:

library(shiny)
server <- function(input, output) {

  output$webshot_image <- renderImage({
    # A temp file to save the output.
    # This file will be removed later by renderImage
    outfile <- tempfile(fileext = '.png')

    # Generate the PNG
    webshot::webshot(url = "https://github.com/rstudio/shiny",
                     file = outfile)

    # Return a list containing the filename
    list(src = outfile,
         contentType = 'image/png',
         width = 400,
         height = 300,
         alt = "This is alternate text")
  }, deleteFile = TRUE)

}

最后的结果是这样的: