如何在闪亮页面内呈现 scatter3d 而不是弹出窗口 [英] How to render scatter3d inside shiny page instead of popup

查看:27
本文介绍了如何在闪亮页面内呈现 scatter3d 而不是弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑在我闪亮的应用程序中实现 3D 交互式绘图,到目前为止我一直在使用 plotly.然而,plotly 有一个主要缺点,它在渲染时非常慢.我已经完成了检查,尽管涉及大量数据集,但更新的 outplot$plot <- renderPlotly ({.....}) 和 plotlyOutput("plot") 的整个创建时间不到 0.5 秒.这是一个多年来已知的问题,但似乎仍然是最新的.

I'm looking at implementing 3D interactive plots in my shiny App, and so far I've been using plotly. However, plotly has one major disadvantage, it's extremely slow when rendering. I've done checks, and the whole creation of updated outplot$plot <- renderPlotly ({.....}) and plotlyOutput("plot") takes less than 0.5 seconds, despite the large data set involved. This is a know issue for years but still seems to be current.

因此,我希望使用一个名为 car 的包,也因为它有很多选项,我特别想要一些其他包中没有的选项.关于汽车包装的信息在这里:http://www.sthda.com/english/wiki/amazing-interactive-3d-scatter-plots-r-software-and-data-visualization问题是它呈现在一个单独的弹出窗口中,而不是在闪亮的应用程序中,我想把它放在里面,或者更好的是,添加一个按钮,允许用户将它作为弹出窗口,但只在被问到时.但是,我不知道如何将 bugger 塞进实际的闪亮页面.

Hence, I'm looking to use a package called car, also because it has many options, some which I particularly want that are not available in other packages. Info on the car package is here: http://www.sthda.com/english/wiki/amazing-interactive-3d-scatter-plots-r-software-and-data-visualization The problem is that it renders in a separate popup window rather than inside the shiny app, and I want to have it inside it, or even better, add a button that allow the user to have it as a popup, but only when asked. However, i can't figure out how to jam the bugger into the actual shiny page.

这是我的最小示例,带有单个文本元素和图形代码(在我的情况下)一直出现在单独的窗口中而不是应用程序中.

Here is my minimal example with a single text element and the graph code that (in my case) keeps appearing in a separate window rather than in the app.

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

There is also this package, scatterplot3d but that's not interactive http://www.sthda.com/english/wiki/scatterplot3d-3d-graphics-r-software-and-data-visualization

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

And there are some RGL packages but they have the same issue (seperate window) and don't offer the options I am lookign for.

推荐答案

您需要使用一个 rglwidget,它获取最后一个 rgl 图并放入一个 htmlwidget.它曾经在一个单独的包中,但最近已被集成到`rgl 中.

You need to use an rglwidget which takes the last rgl plot and puts in in an htmlwidget. It used to be in a separate package, but it has recently been integrated into `rgl.

这是执行此操作的代码:

Here is the code to do this:

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)

屈服于此:

这篇关于如何在闪亮页面内呈现 scatter3d 而不是弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆