3

I'm using plotly's export function to generate png graphs. I installed Shiny Server on an Ubuntu 14.04.

It works on my local computer. It works when I open R from console on the server. However, when I run Shiny app on server, I get PhantomJS error.

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.

I already installed PhantomJS and since I can produce images via R console, i think it exists in PATH.

How can I fix this problem or how can I test to find the problemmatic point?

0

1 Answer 1

8
+50

First, install the webshot package from the terminal on the Ubuntu server:

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

Next, follow the installation description of 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

With this, you should be able use webshot and phantomJS with a Shiny App.

I have tested it with a small sample test app, which I added to /srv/shiny-server/:

the ui.R looks like this:

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")

    )
  )
)

the server.R looks like this:

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)

}

The final result is this:

output_snapshot

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.