daattali / shinyscreenshot

📷 Capture screenshots of entire pages or parts of pages in Shiny apps
https://daattali.com/shiny/shinyscreenshot-demo/
Other
72 stars 8 forks source link

Feasibility of `screenshot` immediate execution? #28

Closed yogat3ch closed 1 year ago

yogat3ch commented 1 year ago

Hi @daattali, We've been experimenting with this package and wondering about the feasibility of something.

We're attempting to use screenshot to save a screenshot inside the shiny.error callback before a shiny session full break in order to capture rich error logs in a zip file that is written to an S3 bucket for debugging purposes. We've observed that screenshot when using the server_dir doesn't actually save the file to the server while the shiny.error callback executes and given the app dies right after the callback concludes, occasionally the screenshot doesn't seem to save at all and isn't available when the files are zipped. Is it possible to force immediate writing of that file to disk? I see that session$sendCustomMessage is used internally to call the JS function that runs html2canvas, is there an alternative that will run immediately? We found a partial workaround by adding the zip and S3 bucket write portions of the logic as a callback to session$onSessionEnded, but occasionally the screenshot won't be available yet. I've asked about this on R4DS if it's easier to discuss there.

Thank you!

daattali commented 1 year ago

Taking a screenshot requires a roundtrip from R --> JS --> R. Whether or not this is all possible within the on.error handler is not a question I can answer, that's a technical question for the shiny team. I don't think there's much that can be done on {shinyscreenshot}'s end -- I would try to ask in the RStudio Community forum if something like this is possible, and hopefully someone from the shiny team would respond.

I'm closing this issue as it's not really a shinyscreenshot issue.