Skip to content

Unrendered plotly plots cause lexical error in app$get_values() #432

@simon-smart88

Description

@simon-smart88

When plotly plots are present in an app but not yet displayed, app$get_values() fails with the error:

{shinytest2} query failed (500)----------------------
URL: http://127.0.0.1:7484/session/74ff996c880f777d410d343fc8aed4aa/dataobj/shinytest?w=&nonce=e18d93f7b&input=1&output=1&export=1&format=rds&sortC=1
<html>

<head lang = "en">
  <title>An error has occurred</title>
</head>

<body>

<h1>An error has occurred!</h1>
<p>lexical error: invalid char in json text.
                                       NULL c("shiny.silent.error", "v
                     (right here) ------^
</p>

</body>
</html>

Please see the examples:

library(shiny)
library(shinytest2)
library(plotly)

shiny_app <- shinyApp(
  fluidPage(
    numericInput("n", "n", 0),
    plotlyOutput("plot")
  ),
  function(input, output) {
    output$plot <- renderPlotly({
      req(input$n > 0)
      plot_ly(cars, x = ~speed, type = "histogram")  
    })  
  }
)

Works fine:

app <- AppDriver$new(shiny_app)
app$set_inputs("n" = 1)
app$get_values()

Does not:

app <- AppDriver$new(shiny_app)
app$get_values()

I am confused because this is currently breaking my tests when they ran fine recently (definitely in 2025) but I have tried with plotly v4.11.0, shinytest2 v0.4.1 and shiny v1.11.1 on another machine and still have the same problem.

> sessionInfo()
R version 4.5.2 (2025-10-31)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 24.04.3 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.12.0 
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.12.0  LAPACK version 3.12.0

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       

time zone: Europe/London
tzcode source: system (glibc)

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

other attached packages:
[1] plotly_4.11.0     ggplot2_4.0.1     shinytest2_0.5.0  testthat_3.3.2    shiny_1.12.1.9000

loaded via a namespace (and not attached):
 [1] sass_0.4.10        generics_0.1.4     tidyr_1.3.2        bspm_0.5.7         digest_0.6.37      magrittr_2.0.3     evaluate_1.0.5     grid_4.5.2         RColorBrewer_1.1-3 fastmap_1.2.0     
[11] jsonlite_2.0.0     processx_3.8.6     brio_1.1.5         ps_1.9.1           promises_1.5.0     httr_1.4.7         purrr_1.2.1        viridisLite_0.4.2  scales_1.4.0       jquerylib_0.1.4   
[21] lazyeval_0.2.2     cli_3.6.5          rlang_1.1.6        cachem_1.1.0       withr_3.0.2        yaml_2.3.12        otel_0.2.0         tools_4.5.2        dplyr_1.1.4        httpuv_1.6.16     
[31] vctrs_0.6.5        R6_2.6.1           mime_0.13          lifecycle_1.0.4    htmlwidgets_1.6.4  pkgconfig_2.0.3    callr_3.7.6        bslib_0.9.0        pillar_1.11.1      later_1.4.2       
[41] gtable_0.3.6       glue_1.8.0         data.table_1.18.0  Rcpp_1.1.0         xfun_0.55          tibble_3.3.1       tidyselect_1.2.1   rstudioapi_0.17.1  knitr_1.51         farver_2.1.2      
[51] xtable_1.8-4       otelsdk_0.2.2      htmltools_0.5.8.1  compiler_4.5.2     S7_0.2.1   

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