在 Shiny 服务器上找不到 PhantomJS

Sab*_*Sab 3 ubuntu r phantomjs shiny-server plotly

我正在使用 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.
Run Code Online (Sandbox Code Playgroud)

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

如何解决此问题或如何进行测试以找到问题点?

cle*_*ens 7

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

sudo su - -c "R -e \"install.packages('webshot')\""
Run Code Online (Sandbox Code Playgroud)

接下来,按照以下安装说明进行操作phantomJS

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
Run Code Online (Sandbox Code Playgroud)

有了这个,你应该能够使用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")

    )
  )
)
Run Code Online (Sandbox Code Playgroud)

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)

}
Run Code Online (Sandbox Code Playgroud)

最终结果是这样的:

输出快照