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

XQuartz and Rayshader Issue #146

Closed
redfoxgis opened this issue Feb 7, 2021 · 11 comments
Closed

XQuartz and Rayshader Issue #146

redfoxgis opened this issue Feb 7, 2021 · 11 comments

Comments

@redfoxgis
Copy link

redfoxgis commented Feb 7, 2021

Amazing software and a true pleasure to use--thank you!

There was an XQuartz update on my Mac a few weeks ago. Ever since that update, I have been unable to use Rayshader. I am not sure if this is an incompatibility issue, an XQuartz issue, or a combination of bad installs of R, and XQuartz. I have tried uninstalling and reinstalling both n times, including using different versions of R and XQuartz. I have tried doing a complete wipe of R (then reinstall) using:

rm -rf /Library/Frameworks/R.framework /Applications/R.app /usr/bin/R /usr/bin/Rscript

R always hangs up indefinitely after calling the rayshader library: library(rayshader)

Here are the R and XQuartz specs that are currently on my Mac:

MacOS Big Sur Version 11.2
XQuartz 2.7.11 (xorg-server 1.18.4)
R version 4.0.3 (2020-10-10) -- "Bunny-Wunnies Freak Out"
Platform: x86_64-apple-darwin17.0 (64-bit)

Any recommendations on how to solve this issue?

@tylermorganwall
Copy link
Owner

tylermorganwall commented Feb 8, 2021

Does rgl work? When you run this code, does R hang?

M <- matrix(rnorm(300), 3, 100, dimnames = list(c('x', 'y', 'z'), 
                                              rep(LETTERS[1:4], 25)))
M <- t(M)
rgl::points3d(M)

I would monitor this issue:

dmurdoch/rgl#11

as it seems like other people may be having similar issues and that thread might have useful information.

@redfoxgis
Copy link
Author

Yes, running that code causes R to hang on my system. Thanks for the reference, I will follow that thread.

@will-rogers
Copy link

@redfoxgis and @tylermorganwall - based on the linked issue above, the best resolve seems to be running
options(rgl.useNULL = TRUE) library(rgl) library(rayshader)

I was able to then run all of the plots from the demo for Rayshader, but you can only (as far as I have seen) render plots using
render_snapshot()

@tylermorganwall
Copy link
Owner

So render_snapshot() does now work when rgl.useNULL = TRUE? Interesting, that's new—that used to produce just a black image.

@will-rogers
Copy link

@tylermorganwall sorry, you're right. I have to additionally run rglwidget() to get the map/plot to render in the R viewer pane. Maybe running render_snapshot is redundant? This renders a 3d, moveable object if I have a 3d plot, but it also returns a nice high res plot for 2d plots. Sorry for the confusion.

@psychemedia
Copy link

psychemedia commented Feb 16, 2021

I've been rendering widgets. movies and videos fine since starting to use rayshader two or three weeks ago, but I seem to have updated something that has now broken render_snapshot() and render_movie() with the error # Error in webshot2::webshot(f1, file = filename, selector = "#webshot", : unused argument (top = FALSE):

library(rgl)
library(rayshader)


options(rgl.useNULL = TRUE,
        rgl.printRglwidget = TRUE)

simple_matrix = matrix(c(0, 0, 0, 0, 0,
                         0, 0, 0, 0, 0,
                         0, 0, 5, 0, 0,
                         0, 0, 0, 0, 0,
                         0, 0, 0, 0, 0), 5)

library(rayrender)

# Open a connection to the renderer
rgl::rgl.open()
rgl::clear3d()

simple_map %>%
  plot_3d(simple_matrix,
          # Change the zscale
          zscale=2,
          # No base
          solid = FALSE
        )

Sys.sleep(0.2)

#render_highquality(samples=200, scale_text_size = 24, clear=FALSE)
hi_quality_fn = "demo_stage_3D_map_overlay_hi.png"
render_snapshot(hi_quality_fn, samples=200,
                scale_text_size = 24, clear=FALSE)

#Close connection
rgl::rgl.close()

knitr::include_graphics(hi_quality_fn)
# Error in webshot2::webshot(f1, file = filename, selector = "#webshot", : unused argument (top = FALSE)

Unpicking...

 capture.output(webshot2::webshot(f1, file = filename, selector = 
"#webshot", vwidth = width + 100, vheight = height, ...), type = 
"message")

rgl::snapshot3d(filename = temp, top = bring_to_front)

render_snapshot(hi_quality_fn, samples = 200, scale_text_size = 24, clear = FALSE)

Ah, so the issue is in rgl::snapshot3d()?

@tylermorganwall
Copy link
Owner

Yes, this was just changed in the latest version of rgl (to use the webshot2 functionality to enable snapshots when rgl.useNULL = TRUE). Probably just an oversight, although I could detect when rgl.useNULL is TRUE and then not pass the top argument myself.

@egayer
Copy link

egayer commented Feb 18, 2021

Python user here, totally amazed by this beautiful package.
I am experiencing the same problem after upgrading XQuartz. I am a sporadic user of R and sorry if my question is naive, but following @wilrogers procedure, by adding rglwidget() after one of the demos code I managed to get a figure that open in a web browser, but no R pane appears.
Would you please help me understand how to use rglwidget() so I can get a nice figure in the R pane ? (in the web browser the figure is not clean, a black line appears from the top of the DEM on one corner and the bottom of it on the other corner)
thanks,

PS: before upgrading XQuartz, everything worked fine : one figure in a R pane, another one in a XQuartz window. Now after upgrading, render_snapshot() gives a black window in the R pane (as mentioned by @tylermorganwall )

@psychemedia
Copy link

@egayer See some of the off-topic comments in dmurdoch/rgl#8 . Issues may boil down to fiddliness related to rgl install, for which there is another open issue: dmurdoch/rgl#26

@quinnpertuit
Copy link

On a Mac, have switched to using rgl::rglwidget to view and save post-rendering.

library(tidyverse)
library(rayshader)
library(rgl)
options(rgl.useNULL=TRUE)

df <- tibble(x = sample(letters,20), y = sample(letters,20), z = runif(20, 1, 10)) %>% mutate_at(vars(x,y),as.factor)

p <- ggplot(df, aes(x=x, y=y, fill=z))+
  geom_tile(na.rm=FALSE)+
  scale_fill_continuous(type = "viridis", na.value='#cfcfcf')+
  theme(legend.position = 'top', panel.background = element_rect(fill='#f0f0fc'))

rgl::clear3d()

plot_gg(p)

rgl::rglwidget()

image

@tylermorganwall
Copy link
Owner

The issues with XQuartz should be fixed in the latest versions of rgl—anyway, it's not a rayshader bug, so I'm going to close this issue.

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

6 participants