Closed mvabl-steve closed 5 years ago
Try looking at this closed issue and see if that solution works:
https://github.com/tylermorganwall/rayshader/issues/32
Are you using on RStudio desktop or server?
Using RStudio Desktop.
I added options(rgl.useNULL = FALSE)
before the libraries, re-opened everything in a new session, and it still yields a big black square.
By the way, thanks for this package! I know I'll get it working, and it's awesome!
Thanks! Did you install the package from github, or from the CRAN?
Github
Try installing from the CRAN and see if it works then.
Hm. Didn't work. I:
"installed over": install.packages("rayshader")
-- NO
remove.packages("rayshader")
; install.packages("rayshader")
. Restart RStudio. -- NO
I'm a self-taught "programmer". There are huge gaps in my knowledge in some really basic stuff. I appreciate your patience. :)
What happens when you have the 3D window open with the visualization and you enter the following code?
tempfilename = paste0(tempfile(), ".png")
rgl::rgl.snapshot(tempfilename)
temppng = png::readPNG(tempfilename)
plot_map(temppng)
I'm not sure what it means to have the 3D window open. I'm just looking at the result in the Viewer pane in RStudio.
If I execute that code immediately after executing
stat_density_2d(aes(x = x, y = depth, fill = stat(nlevel)),
geom = "polygon", n = 100, bins = 10, contour = TRUE) +
facet_wrap(clarity~.) +
scale_fill_viridis_c(option = "A")
par(mfrow = c(1, 2))
plot_gg(ggdiamonds, width = 5, height = 5, raytrace = FALSE, preview = TRUE)
plot_gg(ggdiamonds, width = 5, height = 5, multicore = TRUE, scale = 250,
zoom = 0.7, theta = 10, phi = 30, windowsize = c(800, 800))
render_snapshot(clear = TRUE)
I get the black square all by itself in the Plots panel.
Thanks again for the noob tutorial. :)
Does an external window open when you execute the plot_gg()
function? Are you on Windows, Linux, or MacOS?
MacOS. When I execute plot_gg
the plot renders in RStudio's viewer panel, and it follows the par() instruction. The only time I've ever seen an external window is when I run Shiny apps; then I have a choice where to display.
Open the XQuartz app first and then try running plot_gg(). If you don’t have XQuartz installed, go to https://www.xquartz.org and install it on your system and then try.
😃. But now when I run render_snapshot
, I get
Error in rgl.bringtotop() : 'rgl.bringtotop' failed
Can you post the output of running sessionInfo()
?
R version 3.6.0 (2019-04-26) Platform: x86_64-apple-darwin15.6.0 (64-bit) Running under: macOS 10.15
Matrix products: default BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib
locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages: [1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] rgdal_1.4-4 sp_1.3-1 rgl_0.100.30 rayshader_0.11.5 forcats_0.4.0 stringr_1.4.0 dplyr_0.8.3 purrr_0.3.2
[9] readr_1.3.1 tidyr_0.8.3 tibble_2.1.3 ggplot2_3.2.1 tidyverse_1.2.1
loaded via a namespace (and not attached):
[1] Rcpp_1.0.2 lubridate_1.7.4 lattice_0.20-38 prettyunits_1.0.2 png_0.1-7
[6] assertthat_0.2.1 zeallot_0.1.0 digest_0.6.20 foreach_1.4.7 mime_0.7
[11] R6_2.4.0 imager_0.41.2 tiff_0.1-5 cellranger_1.1.0 plyr_1.8.4
[16] backports_1.1.4 httr_1.4.1 pillar_1.4.2 rlang_0.4.0 progress_1.2.2
[21] lazyeval_0.2.2 readxl_1.3.1 miniUI_0.1.1.1 rstudioapi_0.10 raster_3.0-2
[26] bmp_0.3 labeling_0.3 webshot_0.5.1 htmlwidgets_1.3 igraph_1.2.4.1
[31] munsell_0.5.0 shiny_1.3.2 broom_0.5.2 xfun_0.9 compiler_3.6.0
[36] httpuv_1.5.1 modelr_0.1.5 pkgconfig_2.0.2 htmltools_0.3.6 readbitmap_0.1.5
[41] tidyselect_0.2.5 codetools_0.2-16 viridisLite_0.3.0 crayon_1.3.4 withr_2.1.2
[46] later_0.8.0 MASS_7.3-51.4 grid_3.6.0 xtable_1.8-4 nlme_3.1-141
[51] jsonlite_1.6 gtable_0.3.0 magrittr_1.5 scales_1.0.0 cli_1.1.0
[56] stringi_1.4.3 promises_1.0.1 doParallel_1.0.15 xml2_1.2.2 generics_0.0.2
[61] vctrs_0.2.0 iterators_1.0.12 tools_3.6.0 manipulateWidget_0.10.0 glue_1.3.1
[66] hms_0.5.1 crosstalk_1.0.0 jpeg_0.1-8 parallel_3.6.0 yaml_2.2.0
[71] colorspace_1.4-1 rvest_0.3.4 knitr_1.24 haven_2.1.1
Install the latest version from github and try again. I set the new default where the window doesn't automatically come to the front, so that shouldn't call the rgl.bringtotop
function.
We're up & running. Thank You! By the way, here's how I found/how I plan to use rayshader:
I have an analytics platform for musician revenues. I wanted to turn a lifecycle chart for a musical release into a little sales tool, by 3D printing a version of it across, say, digital platforms (iTunes, Spotify, etc.)
I love that all I had to do was Google "3d render R" and BOOM! -- rayshader (and your blog post on 3D printing).
Thanks Tyler. Some of my friends think I'm a genius. I always tell them that all I do is string together the work of REAL geniuses, like you, Hadley, Mike Bostock, Elijah Meeks, etc.
Great! Sounds cool! Glad I could help and hope rayshader does everything you need it to do. Hopefully you won't encounter any more issues :)
@mvabl-steve
I have an analytics platform for musician revenues. I wanted to turn a lifecycle chart for a musical release into a little sales tool, by 3D printing a version of it across, say, digital platforms (iTunes, Spotify, etc.)
could you possibly show how this looks like? sounds really...useful! screenshot is fine if you don't want to share the code!
Hi, Can you help with my issue please? Simply copying your code just to see if I can adopt if for myself but get this error.
When I try to install plot_gg
Warning in install.packages : package ‘plot_gg’ is not available (for R version 3.6.1)
You need to install the rayshader
package itself, not the function plot_gg()
:
install.packages("rayshader")
Wow thank you! It worked! Although, I could have sworn that I installed rayshader
first and then resorted to plot_gg
because I was getting errors. Nevertheless, thank you!
Mr Morgan-wall, I'm unable to generate a snapshot using the function render_snapshot(). I have rayshader_0.19.2 and I use Windows 10.
This is the error I'm getting:
render_snapshot()
Error in png::readPNG(temp) : file is not in PNG format In addition: Warning messages: 1: In rgl::snapshot3d(filename = temp, top = bring_to_front) : webshot = TRUE requires the webshot2 package; using rgl.snapshot() instead 2: In rgl.snapshot(filename, ...) : RGL: PNG Pixmap Saver Warning: Image width is zero in IHDR 3: In rgl.snapshot(filename, ...) : RGL: PNG Pixmap Saver Warning: Image height is zero in IHDR 4: In rgl.snapshot(filename, ...) : RGL: PNG Pixmap Saver Error: Invalid IHDR data 5: In rgl.snapshot(filename, ...) : RGL: PNG Pixmap Saver Error: an error occured 6: In rgl.snapshot(filename, ...) : 'rgl.snapshot' failed
I try this code:
tempfilename = paste0(tempfile(), ".png") rgl::rgl.snapshot(tempfilename) temppng = png::readPNG(tempfilename) plot_map(temppng)
and I get this message:
tempfilename = paste0(tempfile(), ".png") rgl::rgl.snapshot(tempfilename) Warning messages: 1: In rgl::rgl.snapshot(tempfilename) : RGL: PNG Pixmap Saver Warning: Image width is zero in IHDR 2: In rgl::rgl.snapshot(tempfilename) : RGL: PNG Pixmap Saver Warning: Image height is zero in IHDR 3: In rgl::rgl.snapshot(tempfilename) : RGL: PNG Pixmap Saver Error: Invalid IHDR data 4: In rgl::rgl.snapshot(tempfilename) : RGL: PNG Pixmap Saver Error: an error occured 5: In rgl::rgl.snapshot(tempfilename) : 'rgl.snapshot' failed temppng = png::readPNG(tempfilename) Error in png::readPNG(tempfilename) : file is not in PNG format
With the current GitHub version of ray shader (v. 0.33.3) and - more importantly - the GitHub version of rgl (v 1.0.0), this seems to work (Mac Big Sur 11.2.1, XQuartz 2.8.4)
@tylermorganwall Hi, I also have a problem with render_snapshot():
I've tried rayshader from CRAN, devtools and remotes.
I do this:
elmat %>%
sphere_shade(texture = "desert") %>%
add_water(detect_water(elmat), color = "desert") %>%
add_shadow(ray_shade(elmat, zscale = 3), 0.5) %>%
add_shadow(ambient_shade(elmat), 0) %>%
plot_3d(elmat, zscale = 10, fov = 0, theta = 135, zoom = 0.75, phi = 45, windowsize = c(1000, 800))
Sys.sleep(0.2)
render_snapshot()
When I run this tutorial script from rayshader - either in Jupyter notebook or R studio on Mac M1 - I get this:
Error in load_obj(filename, dir) : attempt to set index 26/26 in SET_VECTOR_ELT
or
Error in load_obj(filename, dir): attempt to set index 26/26 в SET_VECTOR_ELT
Traceback:
1. render_snapshot()
2. render_snapshot_software(filename = temp, cache_filename = cache_filename,
. camera_location = camera_location, camera_lookat = camera_lookat,
. background = background, width = width, height = height,
. light_direction = NULL, fake_shadow = TRUE, text_angle = text_angle,
. text_size = text_size, text_offset = text_offset, print_scene_info = print_scene_info,
. point_radius = point_radius, line_offset = -line_offset,
. fsaa = fsaa, thick_lines = thick_lines, line_radius = line_radius,
. rayvertex_lighting = rayvertex_lighting, rayvertex_lights = rayvertex_lights,
. rayvertex_shadow_map = rayvertex_shadow_map, ...)
3. rayvertex::obj_mesh(cache_filename, position = c(-bbox_center[1],
. -bbox_center[2], -bbox_center[3]))
4. read_obj(filename, materialspath)
5. load_obj(filename, dir)
No idea what is this and how do I come around to solve it. Googling didn't help.
Any help would be appreciated!
Update to the latest version of rayvertex on Github and try again:
remotes::install_github("tylermorganwall/rayvertex")
@tylermorganwall thanks, but this didn't work for me :(
Try the latest version—it should be fixed.
@tylermorganwall Now it works! Thanks a lot for your time and help, Tyler!
I just found rayshader - amazing! Going through the README, and in both of the first 2 examples I have trouble with render_plot(). I'm copy-pasting directly from the README file into RStudio (well, I added a couple library calls):
Here's the result:
I get the same thing with the Monterrey Bay example. Other than render_plot, the other visualizations work fine.
Any clues? Do I need to install something on my Mac? ImageMagick, something like that?