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

Using fig.cur in rgl (or another htmlwidget)? #2241

Closed
dmurdoch opened this issue Mar 16, 2023 · 5 comments · Fixed by #2243
Closed

Using fig.cur in rgl (or another htmlwidget)? #2241

dmurdoch opened this issue Mar 16, 2023 · 5 comments · Fixed by #2243
Assignees

Comments

@dmurdoch
Copy link
Contributor

In rgl I'd like to include alt text in the displays. For regular plots, the alt text is found using the options$fig.cur value to index into options$fig.alt.

This code determines the fig.cur value and uses it to index into fig.alt:

knitr/R/output.R

Lines 495 to 499 in c50d307

if (inherits(x, 'knit_asis_htmlwidget')) {
options$fig.cur = plot_counter()
options = reduce_plot_opts(options)
return(add_html_caption(options, wrap_asis(x, options)))
}

where reduce_plot_opts does the indexing, changing fig.alt and some other options to scalars.

The code is run very late in the rendering process, because not all lines of code that generate plots result in having them shown in the final document: low level changes (like adding annotations to a base plot) suppress the display of the previous plot. By the time this is run for rgl widgets, the data in the widget is fixed, so there's no opportunity for rgl code to see the appropriate alt text.

Would it be possible to include the fig.cur value in some attribute of the div that wraps the widget? Then I could save the whole fig.alt vector in the rgl data, and index into it at rendering time.

Another approach to solve this would be to dispatch to the next method after knit_asis instead of hard-coding the knit_asis_htmlwidget handling.

@dmurdoch
Copy link
Contributor Author

This seems related to #2169, but I don't think fig.id has any effect when displaying an htmlwidget.

@dmurdoch
Copy link
Contributor Author

I have a better suggested change: the add_html_caption function should insert the alt text if it detects that the widget needs it. I will submit a PR for this soon.

@dmurdoch
Copy link
Contributor Author

Thanks! I've tested this, and it's now working fine in the devel version of rgl.

@yihui
Copy link
Owner

yihui commented May 24, 2023

Great! Thanks for testing! I just submitted the dev version to CRAN. Hopefully it will be on CRAN in a couple of days.

Copy link

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants