The rgl package can display scenes in WebGL by calling the rglwidget() function after producing the scene. In RStudio, this displays the scene in the Viewer pane, with the widget automatically sizing itself to the full pane.
In Positron, calling rglwidget() displays the scene in the PLOT pane, but it is displayed in a much bigger virtual pane with scrollbars.
For example:
library(rgl)
example(plot3d)
rglwidget()
shows only the top left of the virtual pane. Sometimes that includes a bit of the plot, other times it's just a white block, because all the interesting stuff is in the middle of the display.
When I do something similar in leaflet, I don't get the scrollbars, so I suspect rgl could work better with Positron. Any idea what changes are needed?
I have some information on this. html widgets have a "sizingPolicy" entry. rgl uses the default setting for it, which has fill = TRUE, viewer$fill = TRUE, and browser$fill = FALSE. Changing browser$fill to TRUE gives me the behaviour I want in Positron. I'm not sure if it does what I'd want in other browsers...
Hmmmm, that's interesting. I also notice that when you do library(rgl) it seems to launch an external ark process, which I've never seen before! Do you know what might be happening on package load that might be doing that?
You might want to check out some of the htmlwidget handling here:
If this object is showing up in the plots pane rather than the viewer pane, then is_plot in there is getting evaluated to TRUE for this example.
I don't know what an "ark" process is. On Unix-like systems, rgl tries to open an X11 window when it starts (to test whether X11 is available), so it might be related to that. I don't think it starts any new process on Windows.
You can suppress the X11 test window by setting options(rgl.useNULL = TRUE) or setting an environment variable RGL_USE_NULL to something like "TRUE". You need to do this before the library(rgl) call.
Is there a recommended way for R code to determine that it's being run in Positron? It would be easy enough to modify the sizing policy conditional on that. More generally, are the functions in "tools:positron" documented and usable by package code?
By the way, x$sizingPolicy$knitr$figure defaults to TRUE in htmlwidgets, and in fact that makes sense for rgl: the figures it draws should act like base plots, except they are 3D and interactive.
I think that in your situation, I would use something like Sys.getenv("POSITRON").
I would say that the functions in tools:positron should be considered internal and not necessarily assumed to not change. If there are functions there that you want to use, it would be better to use the rstudioapi package, since that is documented and usable by other package code: