tylermorganwall / rayshader

R Package for 2D and 3D mapping and data visualization
https://www.rayshader.com/
2.06k stars 214 forks source link

Only the Montereybay example will render #60

Closed dmcairns closed 4 years ago

dmcairns commented 5 years ago

I am new to using rayshader, and I am having trouble getting any example except the Monterey bay example to render at all. For example, the following code does not render the 3d plot:

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

library(rayshader)
library(rgl)

#Here, I load a map with the raster package.
loadzip = tempfile() 
download.file("https://tylermw.com/data/dem_01.tif.zip", loadzip)
localtif = raster::raster(unzip(loadzip, "dem_01.tif"))
unlink(loadzip)

#And convert it to a matrix:
elmat = matrix(raster::extract(localtif,raster::extent(localtif),buffer=1000),
               nrow=ncol(localtif),ncol=nrow(localtif))

ambmat = ambient_shade(elmat)

elmat %>%
  sphere_shade(texture = "desert") %>%
  add_water(detect_water(elmat), color="desert") %>%
  add_shadow(ray_shade(elmat,zscale=3,maxsearch = 300),0.5) %>%
  add_shadow(ambmat,0.5) %>%
  plot_3d(elmat,zscale=10,fov=0,theta=135,zoom=0.75,phi=45, background = 'white')

The following code, however, does render the 3D image in RStudio.

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

require(rayshader)
montereybay %>%
  sphere_shade(zscale = 10, texture = "imhof1") %>%
  add_shadow(ray_shade(montereybay, zscale = 50)) %>%
  add_shadow(ambient_shade(montereybay, zscale = 50)) %>%
  plot_3d(montereybay, zscale = 50, theta = -45, phi = 45, water = TRUE,
          windowsize = c(1000,800), zoom = 0.75, waterlinealpha = 0.3,
          wateralpha = 0.5, watercolor = "lightblue", waterlinecolor = "white") 

I am using RStudio 1.1.456 running on Mohave.

My sessionInfo is:

R version 3.5.1 (2018-07-02)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS  10.14.5

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.5/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] rgl_0.100.24     rayshader_0.10.1

loaded via a namespace (and not attached):
 [1] progress_1.2.2          xfun_0.8                purrr_0.3.2            
 [4] lattice_0.20-35         colorspace_1.4-1        miniUI_0.1.1.1         
 [7] htmltools_0.3.6         yaml_2.2.0              rlang_0.4.0            
[10] manipulateWidget_0.10.0 later_0.8.0             sp_1.3-1               
[13] jpeg_0.1-8              foreach_1.4.4           plyr_1.8.4             
[16] stringr_1.4.0           munsell_0.5.0           raster_2.9-5           
[19] htmlwidgets_1.3         codetools_0.2-15        evaluate_0.14          
[22] knitr_1.23              doParallel_1.0.14       httpuv_1.5.1           
[25] crosstalk_1.0.0         parallel_3.5.1          markdown_1.0           
[28] Rcpp_1.0.1              xtable_1.8-4            promises_1.0.1         
[31] scales_1.0.0            webshot_0.5.1           jsonlite_1.6           
[34] mime_0.7                hms_0.4.2               bmp_0.3                
[37] png_0.1-7               digest_0.6.19           stringi_1.4.3          
[40] tiff_0.1-5              shiny_1.3.2             grid_3.5.1             
[43] rgdal_1.4-4             tools_3.5.1             magrittr_1.5           
[46] crayon_1.3.4            readbitmap_0.1.5        pkgconfig_2.0.2        
[49] prettyunits_1.0.2       imager_0.41.2           assertthat_0.2.1       
[52] rmarkdown_1.13          rstudioapi_0.10         iterators_1.0.10       
[55] R6_2.4.0                igraph_1.2.4.1          compiler_3.5.1

Any help with this will be appreciated. Thanks!

tylermorganwall commented 5 years ago

Does it open an rgl window? Are you running this locally on RStudio desktop, or RStudio server?

dmcairns commented 5 years ago

Your response gave me the clue that I needed to move forward with this. If I open XQuartz before starting RStudio, and open an rgl window with rgl.open() everything works fine. The rgl window is outside of the RStudio (desktop) environment that I am used to using. I still can’t get anything but the Monterrey Bay data to display in the Plots pane of the RStudio interface. Any thoughts on how to get that to show up in the RStudio Plots pane?

Thanks for your help!

Dave Cairns

On Jul 14, 2019, at 5:20 PM, tylermorganwall notifications@github.com wrote:

Does it open an rgl window? Are you running this locally on RStudio desktop, or RStudio server?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_tylermorganwall_rayshader_issues_60-3Femail-5Fsource-3Dnotifications-26email-5Ftoken-3DAMO5BYLOGXWIJTTRVPZGZ3TP7M723A5CNFSM4IASTYQ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZ4HO5Y-23issuecomment-2D511211383&d=DwMCaQ&c=u6LDEWzohnDQ01ySGnxMzg&r=gqMQ-5LYHzGxEfwZbnrVDQ&m=HrHPRYjvUXB1PVddpnKrNyS0h_IT9XKJYL_m9SKCFvs&s=8kgtJ4W3Fwng7x6wIapw_Dmio93vqG7J-YrSmk-SPnI&e=, or mute the thread https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_notifications_unsubscribe-2Dauth_AMO5BYNEIVFDKCCE5VG53OTP7M723ANCNFSM4IASTYQQ&d=DwMCaQ&c=u6LDEWzohnDQ01ySGnxMzg&r=gqMQ-5LYHzGxEfwZbnrVDQ&m=HrHPRYjvUXB1PVddpnKrNyS0h_IT9XKJYL_m9SKCFvs&s=T8qhWJRApj83hZ6RZD3U_rF5gpAYoxuJVnQ6HJiUAJU&e=.

tylermorganwall commented 5 years ago

There isn’t anything special about the Monterey Bay data—it’s simply a matrix. What happens when you replace montereybay with volcano in the examples?