rstudio / shiny

Easy interactive web applications with R
https://shiny.posit.co/
Other
5.35k stars 1.87k forks source link

Error in pngfun #2136

Open KZARCA opened 6 years ago

KZARCA commented 6 years ago

Hi, I have an issue which seems to occur randomly since upgrade from 1.0.5 to 1.1.0. I tried to isolate it without success. It seems to be linked to my slow server running on Ubuntu 16.04 with shiny server, as locally, I don't get any error. I don't have Cairo installed (therefore pngfun is grDevice::png)

Warning: Error in pngfun: argument 'width' incorrect
  123: pngfun
  122: startPNG
  121: drawPlot
  107: <reactive:plotObj>
   91: drawReactive
   78: origRenderFunc
   77: output$distribVars
    1: shiny::runApp

My renderPlot function does not contain any other argument than expr

  output$distribVars <- renderPlot({
    value$plot_distrib
  })
tmastny commented 6 years ago

Hi, thanks for the question. Could you include sessionInfo(), and a small app that reproduces this problem?

KZARCA commented 6 years ago

Hi, I tried to make a reproducible example, but the issue seems to happen randomly on my app. Here is my sessionInfo:

Session info -------------------------------------------------------
 setting  value                       
 version  R version 3.4.4 (2018-03-15)
 system   x86_64, linux-gnu           
 ui       RStudio (1.1.442)           
 language fr_FR                       
 collate  fr_FR.UTF-8                 
 tz       Europe/Paris                
 date     2018-08-01                  

Packages -----------------------------------------------------------
 package        * version  date       source          
 abind            1.4-5    2016-07-21 CRAN (R 3.4.4)  
 arm            * 1.10-1   2018-04-13 cran (@1.10-1)  
 assertthat       0.2.0    2017-04-11 CRAN (R 3.4.4)  
 backports        1.1.2    2017-12-13 CRAN (R 3.4.4)  
 base           * 3.4.4    2018-03-16 local           
 bindr            0.1.1    2018-03-13 cran (@0.1.1)   
 bindrcpp         0.2.2    2018-03-29 cran (@0.2.2)   
 boot           * 1.3-20   2017-07-30 CRAN (R 3.4.4)  
 broom          * 0.4.4    2018-03-29 cran (@0.4.4)   
 car            * 3.0-0    2018-04-02 cran (@3.0-0)   
 carData        * 3.0-1    2018-03-28 cran (@3.0-1)   
 cellranger       1.1.0    2016-07-27 CRAN (R 3.4.4)  
 cli              1.0.0    2017-11-05 CRAN (R 3.4.4)  
 coda             0.19-1   2016-12-08 CRAN (R 3.4.4)  
 colorspace       1.3-2    2016-12-14 CRAN (R 3.4.4)  
 compiler         3.4.4    2018-03-16 local           
 crayon           1.3.4    2017-09-16 CRAN (R 3.4.4)  
 curl             3.2      2018-03-28 cran (@3.2)     
 data.table       1.10.4-3 2017-10-27 cran (@1.10.4-) 
 datasets       * 3.4.4    2018-03-16 local           
 DBI            * 1.0.0    2018-05-02 cran (@1.0.0)   
 dbplyr           1.2.1    2018-02-19 cran (@1.2.1)   
 devtools       * 1.13.5   2018-02-18 CRAN (R 3.4.4)  
 digest           0.6.15   2018-01-28 CRAN (R 3.4.4)  
 dplyr          * 0.7.5    2018-05-19 cran (@0.7.5)   
 evaluate         0.10.1   2017-06-24 CRAN (R 3.4.4)  
 forcats        * 0.3.0    2018-02-19 cran (@0.3.0)   
 foreign          0.8-70   2018-04-23 CRAN (R 3.4.4)  
 GGally         * 1.4.0    2018-05-17 cran (@1.4.0)   
 ggplot2        * 2.2.1    2016-12-30 CRAN (R 3.4.4)  
 glue             1.2.0    2017-10-29 CRAN (R 3.4.4)  
 graphics       * 3.4.4    2018-03-16 local           
 grDevices      * 3.4.4    2018-03-16 local           
 grid             3.4.4    2018-03-16 local           
 gtable           0.2.0    2016-02-26 CRAN (R 3.4.4)  
 haven            1.1.1    2018-01-18 CRAN (R 3.4.4)  
 hms              0.4.1    2018-01-24 CRAN (R 3.4.4)  
 htmltools        0.3.6    2017-04-28 CRAN (R 3.4.4)  
 httpuv           1.4.3    2018-05-10 CRAN (R 3.4.4)  
 httr             1.3.1    2017-08-20 CRAN (R 3.4.4)  
 jomo             2.6-2    2018-04-26 cran (@2.6-2)   
 jsonlite         1.5      2017-06-01 CRAN (R 3.4.4)  
 knitr            1.20     2018-02-20 cran (@1.20)    
 later            0.7.2    2018-05-01 CRAN (R 3.4.4)  
 lattice        * 0.20-35  2017-03-25 CRAN (R 3.4.4)  
 lazyeval         0.2.1    2017-10-29 CRAN (R 3.4.4)  
 lme4           * 1.1-17   2018-04-03 cran (@1.1-17)  
 lubridate        1.7.3    2018-02-27 CRAN (R 3.4.4)  
 magrittr       * 1.5      2014-11-22 CRAN (R 3.4.4)  
 MASS           * 7.3-50   2018-04-30 CRAN (R 3.4.4)  
 Matrix         * 1.2-14   2018-04-09 CRAN (R 3.4.4)  
 memoise          1.1.0    2017-04-21 CRAN (R 3.4.3)  
 methods        * 3.4.4    2018-03-16 local           
 mgcv           * 1.8-23   2018-01-15 CRAN (R 3.4.4)  
 mice           * 3.0.0    2018-05-25 cran (@3.0.0)   
 mime             0.5      2016-07-07 CRAN (R 3.4.4)  
 minqa            1.2.4    2014-10-09 CRAN (R 3.4.4)  
 mitml            0.3-5    2017-03-15 cran (@0.3-5)   
 mnormt           1.5-5    2016-10-15 CRAN (R 3.4.4)  
 modelr           0.1.1    2017-07-24 CRAN (R 3.4.4)  
 munsell          0.4.3    2016-02-13 CRAN (R 3.4.4)  
 nlme           * 3.1-137  2018-04-07 CRAN (R 3.4.4)  
 nloptr           1.0.4    2017-08-22 CRAN (R 3.4.4)  
 nnet             7.3-12   2016-02-02 CRAN (R 3.4.4)  
 openxlsx         4.0.17   2017-03-23 cran (@4.0.17)  
 packrat          0.4.8-1  2016-09-07 CRAN (R 3.4.4)  
 pan              1.4      2016-02-10 cran (@1.4)     
 pander           0.6.1    2017-08-06 CRAN (R 3.4.4)  
 parallel         3.4.4    2018-03-16 local           
 pillar           1.2.1    2018-02-27 CRAN (R 3.4.4)  
 pkgconfig        2.0.1    2017-03-21 CRAN (R 3.4.4)  
 plyr             1.8.4    2016-06-08 CRAN (R 3.4.4)  
 pool           * 0.1.4    2018-03-10 cran (@0.1.4)   
 promises         1.0.1    2018-04-13 CRAN (R 3.4.4)  
 psych            1.8.4    2018-05-06 cran (@1.8.4)   
 purrr          * 0.2.4    2017-10-18 CRAN (R 3.4.4)          
 R6             * 2.2.2    2017-06-17 CRAN (R 3.4.4)  
 RColorBrewer     1.1-2    2014-12-07 CRAN (R 3.4.4)  
 Rcpp             0.12.17  2018-05-18 cran (@0.12.17) 
 readr          * 1.1.1    2017-05-16 CRAN (R 3.4.4)  
 readxl         * 1.1.0    2018-04-20 cran (@1.1.0)   
 reshape          0.8.7    2017-08-06 CRAN (R 3.4.4)  
 reshape2         1.4.3    2017-12-11 CRAN (R 3.4.4)  
 rio              0.5.10   2018-03-29 cran (@0.5.10)  
 rlang          * 0.2.0    2018-02-20 CRAN (R 3.4.4)  
 rmarkdown      * 1.9      2018-03-01 cran (@1.9)     
 RMySQL         * 0.10.15  2018-05-13 cran (@0.10.15) 
 rpart            4.1-13   2018-02-23 CRAN (R 3.4.4)  
 rprojroot        1.3-2    2018-01-03 CRAN (R 3.4.4)  
 rstudioapi       0.7      2017-09-07 CRAN (R 3.4.4)  
 rvest            0.3.2    2016-06-17 CRAN (R 3.4.4)  
 scales         * 0.5.0    2017-08-24 CRAN (R 3.4.4)  
 shiny          * 1.1.0    2018-05-17 cran (@1.1.0)   
 shinydashboard * 0.7.0    2018-03-21 cran (@0.7.0)   
 shinyjs        * 1.0      2018-01-08 cran (@1.0)     
 shinytoastr    * 2.1.1    2016-06-06 CRAN (R 3.4.4)  
 splines        * 3.4.4    2018-03-16 local           
 stats          * 3.4.4    2018-03-16 local           
 stringi          1.2.2    2018-05-02 cran (@1.2.2)   
 stringr        * 1.3.1    2018-05-10 cran (@1.3.1)   
 survival       * 2.42-3   2018-04-16 CRAN (R 3.4.4)  
 tibble         * 1.4.2    2018-01-22 cran (@1.4.2)   
 tidyr          * 0.8.0    2018-01-29 cran (@0.8.0)   
 tidyselect       0.2.4    2018-02-26 CRAN (R 3.4.4)  
 tidyverse      * 1.2.1    2017-11-14 CRAN (R 3.4.4)  
 tools            3.4.4    2018-03-16 local           
 utils          * 3.4.4    2018-03-16 local           
 V8               1.5      2017-04-25 CRAN (R 3.4.4)  
 withr            2.1.2    2018-03-15 CRAN (R 3.4.4)  
 xml2             1.2.0    2018-01-24 CRAN (R 3.4.4)  
 xtable           1.8-2    2016-02-05 CRAN (R 3.4.4)  
 yaml             2.1.19   2018-05-01 cran (@2.1.19)
tmastny commented 6 years ago

Even if the issue happens randomly, it would still be helpful for us to see a small, self-contained example Shiny app that the problems occurs in so we know where to look.

wiwie commented 6 years ago

I see the same issue happening when starting up my app and the div that contains said plot is not yet visible, since its renderUI hasn't been called.

ChristianGeng commented 6 years ago

Hi, I am encountering the same issue (identical trace). I have copied in an example and also the session info.

library(shinydashboard)

# UI Definition - Dashboard page with 'shinydashbard'
ui <- dashboardPage(
  # Header config
  dashboardHeader(title = "Multi tabbed Example"),

  # Sidebar config
  dashboardSidebar(

    #Add sidebar menu with menu items
    sidebarMenu(
      menuItem("Geysir Histograms", tabName = "Geysir", icon = icon("scale", lib = "glyphicon"))
    )
  ),
  # Main Body of the dashboard
  dashboardBody(
    tabItems(
      tabItem(
        tabName = "Geysir",
        fluidRow(
          column(
            width = 6,
            box(
              title = "Select number of bins",
              solidHeader = TRUE,
              collapsible = TRUE,
              width = NULL,
              sliderInput("bins",
                          "Number of bins:",
                          min = 1,
                          max = 50,
                          value = 30)
            ), box(
              title = "PLOT GEYSIR",
              solidHeader = TRUE,
              collapsible = FALSE,
              width = 5,
              uiOutput("distPlot")
            )
          )
        ) # fluidrow
      )
    )

  ) # dashboardBody
) # end dashboard page

# Define server logic required to draw a histogram
server <- function(input, output, session) {
  observe({
    update_geysir_react() #  reactive functions , each in a new lne no comma
    plot_geysir()
  })

  update_geysir_react  <- reactive({
    updateSliderInput(session, "bins")
  })

  plot_geysir <- reactive({

   output$distPlot <- renderPlot({
      # generate bins based on input$bins from ui.R
      x    <- faithful[, 2]
      bins <- seq(min(x), max(x), length.out = input$bins + 1)
      # draw the histogram with the specified number of bins
      hist(x, breaks = bins, col = 'darkgray', border = 'white')
   })
  })
}

shinyApp(ui, server)

SessionInfo output:

R version 3.5.1 (2018-07-02)
Platform: x86_64-suse-linux-gnu (64-bit)
Running under: SUSE Linux Enterprise Server 12 SP3

Matrix products: default
BLAS: /usr/lib64/R/lib/libRblas.so
LAPACK: /usr/lib64/R/lib/libRlapack.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8      
 [8] LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] shinydashboard_0.7.0 LoadRunneR_0.1.0     lubridate_1.7.4      reshape_0.8.7        psych_1.8.4          DT_0.4               shiny_1.1.0          doBy_4.6-2           plotly_4.8.0        
[10] data.table_1.11.4    ggthemes_4.0.1       devtools_1.13.6      pander_0.6.2         knitr_1.20           RODBC_1.3-15         sqldf_0.4-11         RSQLite_2.1.1        gsubfn_0.7          
[19] proto_1.0.0          scales_1.0.0         stringr_1.3.1        tidyr_0.8.1          dplyr_0.7.6          ggplot2_3.0.0        gdata_2.18.0         RPostgreSQL_0.6-2    DBI_1.0.0           

loaded via a namespace (and not attached):
 [1] httr_1.3.1            bit64_0.9-7           jsonlite_1.5          viridisLite_0.3.0     gtools_3.8.1          assertthat_0.2.0      blob_1.1.1            yaml_2.1.19           pillar_1.3.0         
[10] backports_1.1.2       lattice_0.20-35       glue_1.3.0            chron_2.3-52          digest_0.6.17         promises_1.0.1        colorspace_1.3-2      httpuv_1.4.5          htmltools_0.3.6      
[19] Matrix_1.2-14         plyr_1.8.4            pkgconfig_2.0.1       flexdashboard_0.5.1.1 xtable_1.8-2          purrr_0.2.5           later_0.7.3           tibble_1.4.2          withr_2.1.2          
[28] sourcetools_0.1.7     lazyeval_0.2.1        mnormt_1.5-5          mime_0.5              magrittr_1.5          crayon_1.3.4          memoise_1.1.0         evaluate_0.11         nlme_3.1-137         
[37] MASS_7.3-50           xml2_1.2.0            foreign_0.8-70        tools_3.5.1           munsell_0.5.0         bindrcpp_0.2.2        packrat_0.4.9-3       compiler_3.5.1        rlang_0.2.2          
[46] grid_3.5.1            rstudioapi_0.7        htmlwidgets_1.2       tcltk_3.5.1           rmarkdown_1.10        gtable_0.2.0          roxygen2_6.1.0        R6_2.2.2              bit_1.1-14           
[55] bindr_0.1.1           commonmark_1.5        rprojroot_1.3-2       stringi_1.2.4         parallel_3.5.1        Rcpp_0.12.18          tidyselect_0.2.4     
jcheng5 commented 6 years ago

@wiwie It shouldn't attempt to render the plot if it isn't visible, are you using outputOptions to stop suppressing output?

@ChristianGeng I think that's just what happens when the div is too small for quartz to try drawing a plot, can you make it bigger?

wiwie commented 6 years ago

Yes that is true, I was indeed using it. Removing it fixed it for me.

On 14 September 2018 19:00:46 Joe Cheng notifications@github.com wrote:

@wiwie It shouldn't attempt to render the plot if it isn't visible, are you using outputOptions to stop suppressing output? @ChristianGeng I think that's just what happens when the div is too small for quartz to try drawing a plot, can you make it bigger? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

ChristianGeng commented 6 years ago

Thanks very much for the help! It size of div hint helped me to figure it out: I replaced the line "uiOutput("distPlot")" with "plotOutput("distPlot")" in above example. That fixed it for me.

alexanderbuchholz commented 5 years ago

Hello, I am having the same problem as @ChristianGeng. Exactly the same error message. Could somebody help me, please? Thank you very much in advance.

library(shiny)
#library(ggplot2)

ui <- fluidPage(

  # App title ----
  titlePanel("Hello Shiny!"),

  # Sidebar layout with input and output definitions ----
  sidebarLayout(

    # Sidebar panel for inputs ----
    sidebarPanel(

      # Input: Slider for the number of bins ----
      sliderInput(inputId = "bins",
                  label = "Number of bins:",
                  min = 1,
                  max = 50,
                  value = 30)

    ),

    # Main panel for displaying outputs ----
    mainPanel(

      # Output: Histogram ----
      plotOutput(outputId = "distPlot")
      #img(src = "name.png", height = 140, width = 400)

    )
  )
)

# Define server logic required to draw a histogram ----
server <- function(input, output) {

  # Histogram of the Old Faithful Geyser Data ----
  # with requested number of bins
  # This expression that generates a histogram is wrapped in a call
  # to renderPlot to indicate that:
  #
  # 1. It is "reactive" and therefore should be automatically
  #    re-executed when inputs (input$bins) change
  # 2. Its output type is a plot
  output$distPlot <- renderPlot({
    #png(filename="./www/name.png")

    x    <- faithful$waiting
    bins <- seq(min(x), max(x), length.out = input$bins + 1)
    #qplot(x, geom="histogram") 

    hist(x, breaks = bins, col = "#75AADB", border = "white",
         xlab = "Waiting time to next eruption (in mins)",
         main = "Histogram of waiting times")
    #cat(file=stderr(), "drawing histogram with", input$bins, "bins", "\n")
    #dev.off()
  })

}

shinyApp(ui = ui, server = server)

Error:

Listening on http://127.0.0.1:5441
Warning: Error in pngfun: invalid 'width' argument
Stack trace (innermost first):
    90: <reactive:plotObj>
    79: plotObj
    78: origRenderFunc
    77: output$distPlot
     1: runApp
> sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.1 LTS

Matrix products: default
BLAS: /home/alex/anaconda2/lib/R/lib/libRblas.so
LAPACK: /home/alex/anaconda2/lib/R/lib/libRlapack.so

locale:
 [1] LC_CTYPE=en_US.UTF-8          LC_NUMERIC=fr_FR.UTF-8        LC_TIME=fr_FR.UTF-8           LC_COLLATE=en_US.UTF-8        LC_MONETARY=fr_FR.UTF-8      
 [6] LC_MESSAGES=en_US.UTF-8       LC_PAPER=fr_FR.UTF-8          LC_NAME=fr_FR.UTF-8           LC_ADDRESS=fr_FR.UTF-8        LC_TELEPHONE=fr_FR.UTF-8     
[11] LC_MEASUREMENT=fr_FR.UTF-8    LC_IDENTIFICATION=fr_FR.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ggplot2_3.0.0 shiny_1.0.5  

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.18     rstudioapi_0.7   bindr_0.1.1      magrittr_1.5     tidyselect_0.2.4 munsell_0.5.0    colorspace_1.3-2 xtable_1.8-2     R6_2.2.2        
[10] rlang_0.2.1      plyr_1.8.4       dplyr_0.7.6      tools_3.5.1      grid_3.5.1       gtable_0.2.0     withr_2.1.2      htmltools_0.3.6  assertthat_0.2.0
[19] yaml_2.2.0       lazyeval_0.2.1   digest_0.6.15    tibble_1.4.2     crayon_1.3.4     bindrcpp_0.2.2   purrr_0.2.5      later_0.7.3      promises_1.0.1  
[28] glue_1.3.0       mime_0.5         compiler_3.5.1   pillar_1.3.0     scales_0.5.0     jsonlite_1.5     httpuv_1.4.5     pkgconfig_2.0.1 
kmurchison commented 4 years ago

This might help some people.
I had a similar issue when trying to style my app using divs and css. The workaround or fix was to explicitly set the width of the div (fixed pixels or %) so that (I'm guessing here) the rendering process has a predefined width/height to work with. Note: my plot outputs only have height defined server side.

JaninaBistron commented 3 years ago

Thanks. It helped me as well :)