问题描述
不久前,迈克回答了我关于如何将rgl嵌入闪亮的问题,但是我们似乎偶然发现了另一个问题,
Just a short moment ago my question on how to embed an rgl in shiny was answered by Mike, but we seem to have stumbled into another issue,
这是代码示例:
library(rgl)
library(car)
library(shiny)
cars$time <- cars$dist/cars$speed
ui <- fluidPage(
hr("how do we get the plot inside this app window rather than in a popup?"),
rglwidgetOutput("plot", width = 800, height = 600)
)
server <- (function(input, output) {
output$plot <- renderRglwidget ({
rgl.open(useNULL=F)
scatter3d(x=cars$speed, y=cars$dist, z=cars$time, surface=FALSE, ellipsoid = TRUE)
rglwidget()
})
})
shinyApp(ui = ui, server = server)
将rgl.open(useNULL=F)
更改为rgl.open(useNULL=T)
将阻止显示弹出窗口,但是无论哪种情况,闪亮页面中的rgl都会缩放,但不会旋转.
Changing rgl.open(useNULL=F)
to rgl.open(useNULL=T)
will stop the popup from showing, but in either case, the rgl in the shiny page does ZOOM, but doesn't rotate.
似乎鼠标右键单击注册并起作用,而鼠标左键单击未被识别....
It seems that right mouse click registers and works, while left mouse click is not recognized....
> sessionInfo()
R version 3.3.3 (2017-03-06)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] shiny_1.0.0 car_2.1-4 rgl_0.97.0
loaded via a namespace (and not attached):
[1] Rcpp_0.12.9 knitr_1.15.1 magrittr_1.5 splines_3.3.3 MASS_7.3-45 xtable_1.8-2 lattice_0.20-34
[8] R6_2.2.0 minqa_1.2.4 tools_3.3.3 nnet_7.3-12 pbkrtest_0.4-7 parallel_3.3.3 grid_3.3.3
[15] nlme_3.1-131 mgcv_1.8-17 quantreg_5.33 MatrixModels_0.4-1 htmltools_0.3.5 yaml_2.1.14 lme4_1.1-13
[22] digest_0.6.11 Matrix_1.2-8 nloptr_1.0.4 htmlwidgets_0.8 mime_0.5 SparseM_1.77 jsonlite_1.2
[29] httpuv_1.3.3
推荐答案
您的场景正在使用mouseMode"polar"(可能是因为scatter3d正在对其进行设置).该模式目前尚未在rglwidget代码中实现.
Your scene is using mouseMode "polar" (probably because scatter3d is setting it). That mode isn't currently implemented in the rglwidget code.
一种解决方法是在调用rglwidget()之前将mouseMode设置为"trackball",例如在output $ plot中输入以下内容:
A workaround is to set the mouseMode to "trackball" before calling rglwidget(), e.g. in output$plot put this:
open3d(useNULL=TRUE)
scatter3d(x=cars$speed, y=cars$dist, z=cars$time, surface=FALSE, ellipsoid = TRUE)
par3d(mouseMode = "trackball")
rglwidget()
请注意我的我已经简化了上面的代码.要设置鼠标左键,只需指定mouseMode的一个组件即可.
Note my edit: I've simplified the code above. To set the left mouse button, just specify one component of mouseMode.
另一项rgl的最新版本为0.98.8,可在R-forge上使用,最终可能在其他地方使用(请参见),现在已支持极性"鼠标处理.它与R中的行为不同,但是很接近.
Another edit: The latest version of rgl is 0.98.8, available on R-forge and maybe elsewhere eventually (see How do I install the latest version of rgl?), now has support for "polar" mouse handling. It's not identical to the behaviour in R, but it's close.
这篇关于R Shiny中的RGL在鼠标左键单击时未旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!