[Rd] rgl/webGL complains about Javascript, even in recent online docs?

Duncan Murdoch murdoch.duncan at gmail.com
Sat Sep 12 18:42:01 CEST 2015


On 12/09/2015 7:37 AM, Duncan Murdoch wrote:
> On 11/09/2015 10:14 PM, Dominick Samperi wrote:
>> Hello,
>>
>> The recently created online "rgl Overview" at
>> https://cran.r-project.org/web/packages/rgl/vignettes/rgl.html
>> illustrates a problem that I am trying to resolve.
>>
>> At the bottom of each image block on that page appears the
>> advisory: You must enable Javascript to view this page properly.
>>
>> I am using Safari under MacOS with Javascript and WebGL
>> both enabled, so it must be the detection algorithm that is
>> mistaken. It is not clear to me how this works after looking
>> over the generated HTML code (generated by knit2html
>> in my case).
>>
>> I found this after I ran into this problem in a different context,
>> namely, in the process of creating a wordpress page that
>> contains interactive rgl content. I tried simply placing
>> the code generated by knit2html into a wordpress page,
>> but the result is not interactive and that message about
>> Javascript not being enabled appears.
>>
>> On the other hand, if I open the generated code in a
>> browser directly, interaction works and there is no
>> Javascript message.
>>
>> In summary, interactive rgl code works stand-alone, but
>> not in wordpress, and not in the "rgl Overview" page.
>>
> 
> I see the same in Firefox, it's not just Safari.
> 
> If I look at the browser console, I see errors indicating that rglClass
> is not defined, and I don't see a block of Javascript code that should
> have been inserted.
> 
> If I install rgl from the source on CRAN, I see the same problem, so it
> looks like an rgl bug.  I'll see if I can fix it.

Yes, it was an rgl bug.  During my testing I always had knitr loaded
before rgl, but when building the vignettes for the package, the load
order is different, and the initialization was silently skipped.

I'll soon be committing changes to R-forge to fix this, and eventually
it will end up on CRAN.  At the moment it looks like I need to add this
function:

setupKnitr <- function() {
  if (requireNamespace("knitr")) {
    knitr::knit_hooks$set(webgl = hook_webgl)
    knitr::knit_hooks$set(rgl = hook_rgl)
    environment(hook_webgl)$commonParts <- TRUE
    environment(hook_webgl)$reuse <- TRUE
  }
}

and that should be called (just once) near the start of the vignette.

Duncan Murdoch



More information about the R-devel mailing list