Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store the image on the server instead of downloading to the user #6

Open
ferguskeatinge opened this issue Dec 18, 2021 · 1 comment

Comments

@ferguskeatinge
Copy link

Can an option to have the image captured stored on the server, similar to an option in Shinyscreenshot?

"Saving to the server
By default, the image is downloaded to the user's computer and is not stored on the server running the Shiny app. If a server_dir is provided, then the image is stored to this directory on the server. Note that only the directory should be specified, not the file name."

html2canvas encounters CORS issues when screenshotting leaflet maps (some tiles dont load), where i havnt seem to had these issues with domtoimage, but i cant seem to figure out how to store the image on the server (my JS is limited).

Any help would be awesome.

@pvictor
Copy link
Member

pvictor commented Dec 22, 2021

I added an option to send image as base64 string to the server when button is clicked:

capture(
  selector = "#result-block",
  
  filename = NULL, # no download client side
  inputId = "screenshot", # image as base64 string will be available in input$screenshot
  
  icon("camera"), "Take screenshot of results (retrieve server side)",
)

After you can write the image where you want with something like:

write_png <- function(x, filename) {
  x <- sub(".*,", "", x)
  x <- base64enc::base64decode(x)
  png::writePNG(png::readPNG(x), filename)
}
write_png(input$screenshot, "myimage.png")

But currently, the input value is only updated when button is clicked, there's no method to trigger screenshot from the server. (but maybe a combination of hidding the button + shinyjs::click() is sufficient)

Victor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants