gpt4 book ai didi

r - 在 Shiny 的服务器上找不到 PhantomJS

转载 作者:行者123 更新时间:2023-12-04 00:32:39 25 4
gpt4 key购买 nike

我正在使用 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')\""

接下来,关注 installation description 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

有了这个,您应该可以将 webshotphantomJS 与 Shiny App 一起使用。

我已经用一个小的示例测试应用对其进行了测试,我将它添加到 /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)

}

最后的结果是这样的:

output_snapshot

关于r - 在 Shiny 的服务器上找不到 PhantomJS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48702133/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com