wch / webshot

Take screenshots of web pages from R
http://wch.github.io/webshot/
227 stars 40 forks source link

Complex conditionalPanel expressions not handled properly #94

Closed LTLA closed 4 years ago

LTLA commented 4 years ago

It seems that moderately complex conditional expressions inside conditionalPanel are not handled gracefully by appshot(). Consider the following minimal example:

library(shiny)
ui <- fluidPage(
  sidebarPanel(
    checkboxGroupInput("choices", "Choices",
        choices=LETTERS[1:5],
        selected="B"
    ),
    conditionalPanel(condition='(typeof input["choices"] !== "undefined" && input["choices"].includes("A"))',
        textInput("more_stuff", "More stuff", placeholder="Only present if A is selected"))
  ),
  mainPanel(
    uiOutput("stuff")
  )
)

server <- function(input, output) {
  output$stuff<- renderUI({
      HTML(input$choices)
  })
}

app <- shinyApp(ui, server)

This should only show the textbox element if "A" is selected. And indeed, taking a screenshot via a headless chrome browser gives me the expected output:

chromium-browser --headless --disable-gpu --screenshot --run-all-compositor-stages-before-draw http://127.0.0.1:5381/

screenshot

On the other hand, running appshot() gives does not respect the conditional statement:

appshot(app, delay=2, file="webshot.png")

webshot

Of course, I wouldn't be surprised if there was a problem with my JS, but otherwise, I would guess that this stems from some issue with the JS handling in PhantomJS. This is probably unsurprising given its deprecated state, and Googling indicates that PhantomJS does struggle with .includes().

Is there any plan to transition to some kind of headless Chrome? Nothing urgent, but it just seems that depending on deprecated functionality will not be sustainable.

Session information ``` R version 3.6.1 Patched (2019-10-30 r77342) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 18.04.4 LTS Matrix products: default BLAS: /home/luna/Software/R/R-3-6-branch/lib/libRblas.so LAPACK: /home/luna/Software/R/R-3-6-branch/lib/libRlapack.so locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=en_US.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] webshot_0.5.2 shiny_1.4.0.2 loaded via a namespace (and not attached): [1] Rcpp_1.0.4 ps_1.3.2 digest_0.6.25 later_1.0.0 [5] mime_0.9 R6_2.4.1 xtable_1.8-4 jsonlite_1.6.1 [9] magrittr_1.5 rlang_0.4.5 promises_1.1.0 callr_3.4.2 [13] httpuv_1.5.2 fastmap_1.0.1 compiler_3.6.1 processx_3.4.2 [17] htmltools_0.4.0 ```
wch commented 4 years ago

You should take a look at https://github.com/rstudio/webshot2 and https://github.com/rstudio/chromote.

LTLA commented 4 years ago

It's... it's beautiful.

Thanks. This is just what I needed, worked for both the toy example above and for my actual problem. Looking forward to seeing it on CRAN at some point.