gpt4 book ai didi

r - 如何在 Shiny 页面内呈现 scatter3d 而不是弹出窗口

转载 作者:行者123 更新时间:2023-12-01 10:29:40 25 4
gpt4 key购买 nike

我正在考虑在我 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)

还有这个包,scatterplot3d,但不是交互式的
http://www.sthda.com/english/wiki/scatterplot3d-3d-graphics-r-software-and-data-visualization

还有一些 RGL 包,但它们有相同的问题(单独的窗口)并且不提供我正在寻找的选项。

最佳答案

您需要使用 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)

产生这个:

enter image description here

关于r - 如何在 Shiny 页面内呈现 scatter3d 而不是弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44100268/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com