Open cansavvy opened 9 months ago
For example:
We need google slide notes to be captions and vice versa for accessibility and for loqui video making.
So when people set fig.alt this is what happens when you hover your mouse over the image.
But we want this to automatically happen without us specifying a fig.alt option like this:
{r, echo = FALSE, fig.alt= "Major point!! example image"}
ottrpal::include_slide("https://docs.google.com/presentation/d/1YmwKdIy9BeQ3EShgZhvtb3MgR8P6iDX4DfFD65W_gdQ/edit#slide=id.gcc4fbee202_0_141")
Instead, we want to grab from Google slide notes to make the fig.alt so we don't have to specifiy UNLESS we want to OVERRIDE that caption from Google slides.
{r, echo = FALSE}
ottrpal::include_slide("https://docs.google.com/presentation/d/1YmwKdIy9BeQ3EShgZhvtb3MgR8P6iDX4DfFD65W_gdQ/edit#slide=id.gcc4fbee202_0_141")
The flow will look like this:
fig.alt
spec. If not: get_object_id_notes()
). If not: This will involve edits to ottrpal::include_slide
function and things it calls.
Regarding the flow, if the image does NOT have Google Slide notes, should we put something like "Alt text is empty"?
@cansavvy and I tried setting the current code chunk inside include_slide()
with
include_slide <- function(url, output_dir = knitr::opts_chunk$get("fig.path"), overwrite = TRUE, ...) {
# If fig.alt is not set
if (is.null(knitr::opts_current$get("fig.alt")) {
# Insert code to grab the individual google slide notes
gs_notes <- "individual slide notes"
# Unlock opts_current before calling $set()
knitr::opts_current$lock(FALSE)
# Try to set the fig.alt option
knitr::opts_current$set(fig.alt = gs_notes)
# Other ways we tried to set fig.alt:
# options$fig.alt <- gs_notes
# knitr::include_graphics(outfile, fig.alt = gs_notes)
}
outfile <- gs_png_download(url, output_dir, overwrite = overwrite)
knitr::include_graphics(outfile, ...)
}
and failed.
To ask for help, I left a comment on a knitr issue: https://github.com/yihui/knitr/issues/1798#issuecomment-1737986262 and asked on Posit community: https://community.rstudio.com/t/setting-fig-alt-using-knitr-knit-hooks/174159
What about eval
https://stackoverflow.com/a/47399915
@sckott Could you elaborate more? I can't figure out how this relates to the fig.alt
chunk option
If no fig.alt is specified in the options, we want ottrpal to try to grab captions from the google slide notes and use that for the fig.alt option.
This will involve making some tweaks to the
include_slide()
function so that it checks forfig.alt
spec and if none is given usesget_object_id_notes()
function to get the notes and supply those as the fig.alt spec.Happy to pair code on this where needed @howardbaek