【问题标题】:PhantomJS not found on Shiny Server在闪亮的服务器上找不到 PhantomJS
【发布时间】:2018-07-20 00:08:06
【问题描述】:

我正在使用 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 中。

我怎样才能解决这个问题,或者我怎样才能找到问题点?

【问题讨论】:

    标签: r ubuntu phantomjs plotly shiny-server


    【解决方案1】:

    首先,在 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
    

    有了这个,您应该可以将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)
    
    }
    

    最终结果是这样的:

    【讨论】:

      猜你喜欢
      • 2015-05-04
      • 2017-07-05
      • 1970-01-01
      • 2018-08-10
      • 2014-05-06
      • 2016-12-28
      • 1970-01-01
      • 2021-12-22
      • 2014-10-01
      相关资源
      最近更新 更多