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

When using webshot2 in Rmd to html, hyperlink the URL? #10

Open
maelle opened this issue Jan 23, 2020 · 3 comments
Open

When using webshot2 in Rmd to html, hyperlink the URL? #10

maelle opened this issue Jan 23, 2020 · 3 comments

Comments

@maelle
Copy link

maelle commented Jan 23, 2020

I'm not too sure whether this is a feature request or something I should know how to do. :-)

I'm using webshot2::webshot() in an Rmd rendering to html (bookdown, but it could be another html format) and would like the image to have an hyperlink to the URL that's been screenshot. How could this work?

@wch
Copy link
Collaborator

wch commented Jan 23, 2020

There's a knit_print.webshot method:

webshot2/R/webshot.R

Lines 283 to 289 in 03a0fbd

knit_print.webshot <- function(x, ...) {
lapply(x, function(filename) {
res <- readBin(filename, "raw", file.size(filename))
ext <- gsub(".*[.]", "", basename(filename))
structure(list(image = res, extension = ext), class = "html_screenshot")
})
}

It creates an object with class html_screenshot, which is used by knitr or rmarkdown somehow (I don't know how that part works). In knitr, it sets the url of the object. Maybe the same can be done in knit_print.webshot? https://github.com/yihui/knitr/blob/ab191b07223a609e7c4ba53d664d35ebfc9dcb97/R/plot.R#L514-L517

You may also be able to define your own knit_print.webshot method in your document (though I'm not 100% sure that works anymore due to some recent changes in how R does S3 dispatch).

@maelle
Copy link
Author

maelle commented Jan 29, 2020

Thank you, sorry, I still need to explore this. I can update this thread then but I won't be hurt if you close the issue.

@maelle
Copy link
Author

maelle commented Feb 5, 2020

Do the args used to create a webshot object stay attached to it somehow? I tried looking but was a bit out of my depth 😅

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