shinyscreenshot icon indicating copy to clipboard operation
shinyscreenshot copied to clipboard

"resolved is undefined" error with screenshotButton in shinylive

Open barryrowlingson opened this issue 2 years ago • 9 comments

I've been asked to get a shiny app running on shinylive (in-browser running of shiny apps via webr) and I get this error image:

image

unless I comment out the screenshotButton call in the ui section, in which case the app works fine in the browser.

I can only guess this is because of the way browser screenshot code works, and its beyond me to debug it at this time. My main motivation for reporting it here is so if anyone searches for "shinylive resolved is undefined" they can see this and it will save them a bunch of debugging to discover the issue is with screenshotButton.

barryrowlingson avatar Jan 04 '24 16:01 barryrowlingson

Thanks for the report. I have no clue how to debug within shinylive, was there any error log anywhere? Either in javascript or elsewhere?

daattali avatar Jan 05 '24 00:01 daattali

I've just discovered in a minimal shiny app that adding an actionButton to the ui and using screenshot in the server works in shinylive, whereas screenshotButton in the ui fails. If that's fully equivalent to the screenshotButton then I'll go with that, assuming I can get that working in the app I'm trying to make work. Hopeful!

There are lots of "error" messages on the browser console but they happen even when a shinylive app is working perfectly. The only extra errors are these two entries and the scary skeleton face in the browser:

preload error:resolved is undefined shinylive.js:34938:38
    _error http://127.0.0.1:7446/shinylive/shinylive.js:34938
    error http://127.0.0.1:7446/shinylive/shinylive.js:34944
    runRAsync http://127.0.0.1:7446/shinylive/shinylive.js:33571
resolved is undefined shinylive.js:34794:19
    runApp2 http://127.0.0.1:7446/shinylive/shinylive.js:34794

barryrowlingson avatar Jan 05 '24 10:01 barryrowlingson

They have extremely similar paths, that end up in the same place, and they're meant to be as identical as possible. Any difference that you see between the two is not be design, so yes if you can make it work with one of them then you should use it. I really don't know how to even begin debugging this in shinylive

daattali avatar Jan 20 '24 07:01 daattali

It appears the core issue may have been fixed: the example in the shinyscreenshot README appears to work in shinylive. Or, at least it doesn't fail loudly. It does have trouble loading Shiny's CSS files so the screenshots aren't great. But the core functionality seems to be working.

https://shinylive.io/r/editor/#code=NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAGwEsAjAJykYE8AKAZwAtaJWAlAB0IdJiw48+rTgUZwKPIqWEQRAV1oACADwBaLQDNqmgCYAFKAHM47EVq3kAHqQCSEVOtJ2wz0kLwtAIBRMjhGLU4ieEc4FwDcIN84Tn8wAVx7LSgCUloSACEvUhIfKyIEpIAVKABrOGzIuQUIJTTVVRFOcIA3cN0DQ3UIXPyIdj5PUkSiLymBLRAsonpuxj7gvrIJjy8AEnLEpYgHB1l5RW5ldlUHAF9VO5Eu3n4AQXR2TUS1vsYBMB3AC6QA

gadenbuie avatar Jul 01 '24 19:07 gadenbuie

It does seem that this issue is working now, works for me. @barryrowlingson can you confirm you can use screenshotButton() now?

daattali avatar Jul 02 '24 23:07 daattali

@gadenbuie any idea why CSS files are not being loaded when using shinylive? Is this something that can be fixed?

Code:

library(shiny)
library(shinyscreenshot)

ui <- fluidPage(
  textInput("text", "Enter some text", "test"),
  actionButton("go", "Take a screenshot")
)

server <- function(input, output) {
  observeEvent(input$go, {
    screenshot()
  })
}

shinyApp(ui, server)

daattali avatar Jul 02 '24 23:07 daattali

I don't know exactly why, but I suspect it'll be tricky to fix. The Shiny app is running in a service worker and I think that html2canvas also uses a service worker, so without some additional work (vague and ambiguous because I don't know exactly what work) the html2canvas service worker isn't allowed to request resources from Shiny's service worker.

gadenbuie avatar Jul 03 '24 17:07 gadenbuie

As far as I can tell, html2canvas does not use service workers. Anyway, I imagine this is not something Posit will dedicate too much more time investing, so I should just accept that shinylive is not supported for this package, right?

daattali avatar Jul 08 '24 03:07 daattali

As far as I can tell, html2canvas does not use service workers.

Ah, sorry, I thought I saw documentation saying it did but now I can't find it.

gadenbuie avatar Jul 08 '24 14:07 gadenbuie