Skip to content

rgl displays not showing up #85

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

Open
dmurdoch opened this issue Apr 12, 2025 · 4 comments
Open

rgl displays not showing up #85

dmurdoch opened this issue Apr 12, 2025 · 4 comments

Comments

@dmurdoch
Copy link

dmurdoch commented Apr 12, 2025

I just had a report that the vignettes in rgl are not displaying the graphics properly. They were using R Markdown and markdown::html_format as the output driver, and that stopped working with this commit rstudio/markdown@b4c328d to that package.

For example, this vignette: https://github.com/dmurdoch/rgl/blob/8e12a29031f2b0e52fc204cc1b947fcdabd6bdf0/vignettes/transparency.Rmd should display movable shapes, but it just displays blank blocks now.

Of course, markdown is no longer being maintained so I can't post an issue there, and I tried to follow the instructions to use litedown::html_format instead, with no luck.

I can switch rgl back to using rmarkdown::html_vignette; it still works, but I liked avoiding Pandoc with markdown::html_format, and from the design goals, it seems like litedown should suit me if I can figure out how to get it to work.

I think the things I need to know are necessary changes to knit_print methods and sew methods to work in litedown (and maybe changes to code to detect that I'm in litedown). Are those documented anywhere?

@yihui
Copy link
Owner

yihui commented Apr 15, 2025

I'm glad that you asked. This is an area where I haven't decided what to do yet. I'd like to give package authors a way to register their CSS/JS assets for their widgets, so litedown can pick them up and automatically insert them to the HTML <head>.

For now, the public API I have provided is litedown::vest(), to which you can pass CSS/JS paths. This is a manual approach. That is, the Rmd document authors need to know which CSS/JS assets they need for their documents (there are some examples here: https://yihui.org/litedown/#sec:simple-dt). This is definitely not a reasonable requirement to users.

I do have internal API to register CSS/JS, but I'd like to know if vest() works for you before publicizing the internal mechanism. You can do a quick test.

@dmurdoch
Copy link
Author

I'm not sure if vest() will be enough. I'm working through some tests with leaflet, which might be a bit easier than rgl, but I hit this snag. When I try to call vest on one of its dependencies, I get this error:

litedown::vest(css = "/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/leaflet/htmlwidgets/lib/leaflet/leaflet.css")
Error in file(con, "rb") : cannot open the connection

That file definitely exists; it was obtained using system.file("htmlwidgets/lib/leaflet/leaflet.css", package = "leaflet"). I can't quite follow what it is trying to do: it appears to read the file, then litedown:::resolve_url() ends up being called, and it dies.

@dmurdoch
Copy link
Author

I have a fix for the issue above, but I think I don't understand the intention of the original code, so it might cause other problems. The original code that goes wrong looks like this:

litedown/R/utils.R

Lines 1290 to 1308 in 637bdf0

is_web = is_https(x)
is_rel = !is_web && is_rel_path(x)
if (is_web && embed_https && xfun::url_filename(x) == 'MathJax.js') {
warning('MathJax.js cannot be embedded. Please use MathJax v3 instead.')
embed_https = FALSE
}
# linking for 1) local rel paths that don't need to be embedded, or 2) web
# resources that don't need to be accessed offline
link1 = is_rel && !embed_local
link2 = is_web && !embed_https
if (link1 || link2) {
if (link2) x = download_url(
x, offline, handler = function(code) resolve_url(x, code, ext, FALSE)
)
sprintf(t1, x)
} else {
# embedding for other cases
one_string(c(t2[1], resolve_external(x, is_web, ext), t2[2]))
}

Here x is supposed to be the a filename or URL pointing to a dependency to link or include. When x is an absolute file path, none of is_web, is_rel, link1 or link2 are true, so the contents should be inserted, and that's what happens at the end with the call to resolve_external(). However, that function sees some content in the leaflet file that makes it think it needs to download something, and then things go wrong.

What I don't understand is the logic that relative paths should be distinguished from absolute paths. My example works fine if litedown just reads and inserts the file when is_web is FALSE.

yihui added a commit that referenced this issue Apr 26, 2025
…operty; this fixes the leaflet.css error in #85
@yihui
Copy link
Owner

yihui commented Apr 26, 2025

The error was due to this line in leaflet.css (which uses an obsolete behavior property): https://github.com/rstudio/leaflet/blob/947ea176d177fe519ac6d6a9a2366bef033c4c81/inst/htmlwidgets/lib/leaflet/leaflet.css#L109 The R package leaflet is still using a version of leaflet.js that is 8 years old, and the current leaflet.js no longer contains that behavior property: https://github.com/Leaflet/Leaflet/blob/main/dist/leaflet.css

I have excluded the behavior property when embedding url() resources in CSS, so the above leaflet.css should work now.

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