作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在考虑在我 Shiny 的应用程序中实现 3D 交互式绘图,到目前为止我一直在使用 plotly。然而,plotly 有一个主要缺点,它在渲染时非常慢。
我已经完成了检查,尽管涉及大量数据集,但更新后的 outplot$plot <- renderPlotly ({.....}) 和 plotlyOutput("plot") 的整个创建时间不到 0.5 秒。这是一个多年来已知的问题,但似乎仍然是最新的。
因此,我希望使用一个名为 car 的包,也因为它有很多选项,我特别想要一些其他包中没有的选项。关于汽车包装的信息在这里:http://www.sthda.com/english/wiki/amazing-interactive-3d-scatter-plots-r-software-and-data-visualization
问题是它呈现在一个单独的弹出窗口中,而不是在 Shiny 的应用程序中,我希望将它放在其中,或者更好的是,添加一个按钮,允许用户将其作为弹出窗口,但仅在被询问时。但是,我不知道如何将 bugger 塞入实际的 Shiny 页面。
这是我的最小示例,带有单个文本元素和图形代码(在我的情况下)一直出现在单独的窗口中而不是应用程序中。
install.packages(c("rgl", "car", "shiny"))
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?"),
plotOutput("plot", width = 800, height = 600)
)
server <- (function(input, output) {
output$plot <- renderPlot({
scatter3d(x=cars$speed, y=cars$dist, z=cars$time, surface=FALSE, ellipsoid = TRUE)
})
})
shinyApp(ui = ui, server = server)
最佳答案
您需要使用 rglwidget
它采用最后一个 rgl 图并放入 htmlwidget
.它曾经在一个单独的包中,但最近已被集成到`rgl 中。
这是执行此操作的代码:
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=T)
scatter3d(x=cars$speed, y=cars$dist, z=cars$time, surface=FALSE, ellipsoid = TRUE)
rglwidget()
})
})
shinyApp(ui = ui, server = server)
关于r - 如何在 Shiny 页面内呈现 scatter3d 而不是弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44100268/
我是一名优秀的程序员,十分优秀!