Strange bug when You use Plotly on Your own server

I used my Shiny apps only locally and only with in the past, but now I’ve got a VPS. When I migrated my previous apps to the VPS I found a strange bug. When there was ggplot based Plotly plot in my code I got an error message: “An error has occurred. Check your logs or contact the app author for clarification.”.

I checked the log file which said:

Warning: Error in : cannot open file 'Rplots.pdf'
Stack trace (innermost first):
    87: grid.Call
    86: convertUnit
    85: convert
    84: unitConvert
    83: %||%
    82: gg2list
    81: ggplotly.ggplot
    80: ggplotly
    79: ggplotly [/srv/shiny-server/survey_from_gf/server.R#136]
    78: func
    77: origRenderFunc
    76: output$plotlyBar
     1: runApp

Fortunately I found this blog post which says I just only need to paste pdf(NULL) to my code which solves the problem.

So if You have a same issue You just only need to paste it to the start of the renderPlotly function like this:

  function(input, output) {
     output$plotlyPlot <- renderPlotly({
        ggplot(mtcars, aes(factor(cyl))) +

Write me if You know a more elegant way to fix this bug.

One Reply to “Strange bug when You use Plotly on Your own server”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.