包rglwidget的例子相当复杂;我在下面创建了一个简单的shiny / rglwidget示例.该图显示正常,但每次切换复选框时,浏览器窗口中都会附加一个新图像.
如何更换/覆盖第一个图?
options(rgl.useNULL = TRUE)
library(shiny)
library(rglwidget)
library(rgl)
app = shinyApp(
ui = bootstrapPage(
checkboxInput("rescale", "Rescale"),
rglwidgetOutput("rglPlot")
),
server = function(input, output) {
output$rglPlot <- renderRglwidget({
try(rgl.close()) # added following @user2554330
if (input$rescale) aspect3d(1,1,10) else aspect3d(1,1,1)
# High level function following @user2554330: same effect
# plot3d(rnorm(100), rnorm(100), rnorm(100,sd = 0.1),
# col = rainbow(1000))
spheres3d(rnorm(100), rnorm(100), rnorm(100,sd = 0.1), col = "red",
radius = 0.1)
axes3d()
rglwidget()
})
})
runApp(app)
会话信息:
R version 3.2.2 (2015-08-14)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252
[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
[5] LC_TIME=German_Germany.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] rgl_0.95.1429 rglwidget_0.1.1431 shiny_0.12.2
loaded via a namespace (and not attached):
[1] htmlwidgets_0.5.1 R6_2.1.1 rsconnect_0.4.1.9 htmltools_0.2.7
[5] tools_3.2.2 yaml_2.1.13 Rcpp_0.12.2 knitr_1.11
[9] jsonlite_0.9.19 digest_0.6.8 xtable_1.8-0 Cairo_1.5-9
[13] httpuv_1.3.3 mime_0.4
最佳答案 它就像rgl一样 – 当你使用低级命令(spheres3d,axes3d)时,它们被添加到现有的图中.如果要替换它,最简单的方法是首先调用rgl.close(). next3d()是另一种可能性,虽然它略有不同.
或者,调用plot3d或persp3d等高级函数.他们在画画前清理窗户.
编辑补充:我上面描述的是应该发生的事情.我看到重复的输出;他们是个错误.我在R-forge的版本0.1.1433中修复了它.