Skip to content

Snapshot function errors when the output itself is error #1685

Open

Description

@rfaelens

Plotly uses snapshotPreprocessOutput to remove any output values that are randomly generated. This is great.

However, if the render function outputs an error, the result is not a valid JSON. Because of this, the snapshotPreprocessOutput function errors out and frameworks like shinytest error out as well.

Example code:

library(plotly)
ui <- fluidPage(
  checkboxInput("go", label="Render plot"),
  plotlyOutput("plot")
)
server <- function(input, output, session) {
  output$plot_plotly <- renderPlotly({
    shiny::req(input$go) #induce a silent.error if input$go is FALSE
    ggplot(data.frame(x=rnorm(1000))) + 
      geom_histogram(aes(x=x))
  })
}
shinyApp(ui=ui, server=server)

Test code:

library(shinytest)
app <- ShinyDriver$new(path="tmp/")
app$getAllValues()

app$getAllValues() reports an error, because fetching the snapshot URL reports an error 500.

The issue can be easily solved in
https://github.com/ropensci/plotly/blob/bcae42bbeea8d8368fb3ca881243e6acd0c661b4/R/shiny.R#L58
I suggest you check if value is a character string before parsing as JSON.

Activity

  1. cpsievert commented on Feb 6, 2020

    @cpsievert
    Collaborator

    Hmm, strange, when I run your example I don't see an error:

    > library(shinytest)
    > app <- ShinyDriver$new(path="tmp/")
    > app$getAllValues()
    
    $input
    $input$go
    [1] FALSE
    
    $output
    named list()
    
    $export
    named list()

    If you don't mind, it'd be great if you could try again with the development version of plotly -- remotes::install_github("ropensci/plotly") and the CRAN version of shinytest install.packages("shinytest"). If you still are encountering an error, please include devtools::session_info() and app$getDebugLog()

  2. nouvrita commented on Feb 13, 2020

    @nouvrita

    There is an error in the example code. Instead of plotlyOutput("plot") : plotlyOutput("plot_plotly").
    With this modification, I get also the error.

    Here is my devtools::session_info() :

    - Session info ----------------------------------------------------------------------------------
     setting  value                       
     version  R version 3.6.2 (2019-12-12)
     os       Windows 10 x64              
     system   x86_64, mingw32             
     ui       RStudio                     
     language (EN)                        
     collate  French_France.1252          
     ctype    French_France.1252          
     tz       Europe/Paris                
     date     2020-02-13                  
    
    - Packages --------------------------------------------------------------------------------------
     package     * version date       lib source                          
     assertthat    0.2.1   2019-03-21 [1] CRAN (R 3.6.1)                  
     backports     1.1.5   2019-10-02 [1] CRAN (R 3.6.1)                  
     base64enc     0.1-3   2015-07-28 [1] CRAN (R 3.6.0)                  
     callr         3.4.0   2019-12-09 [1] CRAN (R 3.6.2)                  
     cli           2.0.1   2020-01-08 [1] CRAN (R 3.6.1)                  
     colorspace    1.4-1   2019-03-18 [1] CRAN (R 3.6.1)                  
     crayon        1.3.4   2017-09-16 [1] CRAN (R 3.6.1)                  
     crosstalk     1.0.0   2016-12-21 [1] CRAN (R 3.6.1)                  
     curl          4.3     2019-12-02 [1] CRAN (R 3.6.1)                  
     data.table    1.12.8  2019-12-09 [1] CRAN (R 3.6.2)                  
     debugme       1.1.0   2017-10-22 [1] CRAN (R 3.6.2)                  
     desc          1.2.0   2018-05-01 [1] CRAN (R 3.6.1)                  
     devtools      2.2.1   2019-09-24 [1] CRAN (R 3.6.1)                  
     digest        0.6.23  2019-11-23 [1] CRAN (R 3.6.2)                  
     dplyr         0.8.4   2020-01-31 [1] CRAN (R 3.6.2)                  
     ellipsis      0.3.0   2019-09-20 [1] CRAN (R 3.6.1)                  
     fansi         0.4.1   2020-01-08 [1] CRAN (R 3.6.1)                  
     fastmap       1.0.1   2019-10-08 [1] CRAN (R 3.6.1)                  
     fs            1.3.1   2019-05-06 [1] CRAN (R 3.6.1)                  
     ggplot2     * 3.2.1   2019-08-10 [1] CRAN (R 3.6.1)                  
     glue          1.3.1   2019-03-12 [1] CRAN (R 3.6.1)                  
     gtable        0.3.0   2019-03-25 [1] CRAN (R 3.6.1)                  
     htmltools     0.4.0   2019-10-04 [1] CRAN (R 3.6.1)                  
     htmlwidgets   1.5.1   2019-10-08 [1] CRAN (R 3.6.1)                  
     httpuv        1.5.2   2019-09-11 [1] CRAN (R 3.6.1)                  
     httr          1.4.1   2019-08-05 [1] CRAN (R 3.6.1)                  
     jsonlite      1.6.1   2020-02-02 [1] CRAN (R 3.6.2)                  
     labeling      0.3     2014-08-23 [1] CRAN (R 3.6.0)                  
     later         1.0.0   2019-10-04 [1] CRAN (R 3.6.1)                  
     lazyeval      0.2.2   2019-03-15 [1] CRAN (R 3.6.1)                  
     lifecycle     0.1.0   2019-08-01 [1] CRAN (R 3.6.2)                  
     magrittr      1.5     2014-11-22 [1] CRAN (R 3.6.1)                  
     memoise       1.1.0   2017-04-21 [1] CRAN (R 3.6.1)                  
     mime          0.9     2020-02-04 [1] CRAN (R 3.6.2)                  
     munsell       0.5.0   2018-06-12 [1] CRAN (R 3.6.1)                  
     parsedate     1.2.0   2019-05-08 [1] CRAN (R 3.6.2)                  
     pillar        1.4.3   2019-12-20 [1] CRAN (R 3.6.2)                  
     pingr         2.0.0   2019-10-21 [1] CRAN (R 3.6.2)                  
     pkgbuild      1.0.6   2019-10-09 [1] CRAN (R 3.6.1)                  
     pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 3.6.1)                  
     pkgload       1.0.2   2018-10-29 [1] CRAN (R 3.6.1)                  
     plotly      * 4.9.2   2020-02-13 [1] Github (ropensci/plotly@a63b048)
     png           0.1-7   2013-12-03 [1] CRAN (R 3.6.0)                  
     prettyunits   1.1.0   2020-01-09 [1] CRAN (R 3.6.2)                  
     processx      3.4.1   2019-07-18 [1] CRAN (R 3.6.1)                  
     promises      1.1.0   2019-10-04 [1] CRAN (R 3.6.1)                  
     ps            1.3.0   2018-12-21 [1] CRAN (R 3.6.1)                  
     purrr         0.3.3   2019-10-18 [1] CRAN (R 3.6.1)                  
     R6            2.4.1   2019-11-12 [1] CRAN (R 3.6.1)                  
     Rcpp          1.0.3   2019-11-08 [1] CRAN (R 3.6.1)                  
     rematch       1.0.1   2016-04-21 [1] CRAN (R 3.6.1)                  
     remotes       2.1.0   2019-06-24 [1] CRAN (R 3.6.1)                  
     rlang         0.4.4   2020-01-28 [1] CRAN (R 3.6.2)                  
     rprojroot     1.3-2   2018-01-03 [1] CRAN (R 3.6.1)                  
     rstudioapi    0.10    2019-03-19 [1] CRAN (R 3.6.1)                  
     scales        1.1.0   2019-11-18 [1] CRAN (R 3.6.1)                  
     sessioninfo   1.1.1   2018-11-05 [1] CRAN (R 3.6.1)                  
     shiny       * 1.4.0   2019-10-10 [1] CRAN (R 3.6.1)                  
     shinytest   * 1.3.1   2019-05-06 [1] CRAN (R 3.6.2)                  
     showimage     1.0.0   2018-01-24 [1] CRAN (R 3.6.2)                  
     testthat      2.3.1   2019-12-01 [1] CRAN (R 3.6.1)                  
     tibble        2.1.3   2019-06-06 [1] CRAN (R 3.6.1)                  
     tidyr         1.0.2   2020-01-24 [1] CRAN (R 3.6.2)                  
     tidyselect    1.0.0   2020-01-27 [1] CRAN (R 3.6.2)                  
     usethis       1.5.1   2019-07-04 [1] CRAN (R 3.6.1)                  
     vctrs         0.2.2   2020-01-24 [1] CRAN (R 3.6.2)                  
     viridisLite   0.3.0   2018-02-01 [1] CRAN (R 3.6.1)                  
     webdriver     1.0.5   2018-04-11 [1] CRAN (R 3.6.2)                  
     withr         2.1.2   2018-03-15 [1] CRAN (R 3.6.1)                  
     xtable        1.8-4   2019-04-21 [1] CRAN (R 3.6.1)                  
     yaml          2.2.1   2020-02-01 [1] CRAN (R 3.6.2)   
               
    
    [1] C:/Users/md95561/Documents/R/win-library/3.6
    [2] C:/Program Files/R/R-3.6.2/library
    

    And my app$getDebugLog() :

    S/I 09:16:08.00 window.shinytest loaded
    S/I 09:16:08.00 already connected
    S/I 09:16:08.00 ready
    S/I 09:16:08.00 idle
    C/E ----------- Running application in test mode.
    C/E ----------- Le chargement a nécessité le package : shiny
    C/E ----------- Le chargement a nécessité le package : ggplot2
    C/E ----------- 
    C/E ----------- Attachement du package : 'plotly'
    C/E ----------- 
    C/E ----------- The following object is masked from 'package:ggplot2':
    C/E ----------- 
    C/E -----------     last_plot
    C/E ----------- 
    C/E ----------- The following object is masked from 'package:stats':
    C/E ----------- 
    C/E -----------     filter
    C/E ----------- 
    C/E ----------- The following object is masked from 'package:graphics':
    C/E ----------- 
    C/E -----------     layout
    C/E ----------- 
    C/E ----------- 
    C/E ----------- Listening on http://127.0.0.1:4538
    C/E ----------- Warning in is.na(x) :
    C/E -----------   is.na() appliqué à un objet de type 'closure' qui n'est ni une liste, ni un vecteur
    C/E ----------- Warning: Error in : lexical error: invalid char in json text.
    C/E -----------                                        NULL c("shiny.silent.error", "v
    C/E -----------                      (right here) ------^
    C/E ----------- 
    C/E -----------   [No stack trace available]
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions