我可以用ggplotly与scattergl?

yc0p9oo0  于 2023-10-13  发布在  其他
关注(0)|答案(1)|浏览(104)

我想在一个闪亮的应用程序中创建一个带有套索选择的绘图。然而,即使只有1000点的响应时间是无法忍受的。我读到有人可以使用scattergl来提高响应速度,但我没有找到任何使用ggplotly的选项。这是一个耻辱,因为我想使用我已经构建的ggplot。
这里有一些代码来复制:

library(shiny)
library(shinyjs)
library(plotly)
library(ggplot2)

N <- 10e3

ui <- fluidPage(
  plotlyOutput("p"),
  plotlyOutput("p10"),
  plotlyOutput("p100"),
  plotlyOutput("p2"),
  plotlyOutput("p3"),
  plotlyOutput("p3_"),
)

server <- function(input, output, session) {
  output$p100 <- renderPlotly({
    plot_ly(type="scattergl",mode="markers", x=rnorm(100*N), y=rnorm(100*N))
  })
  output$p10 <- renderPlotly({
    plot_ly(type="scattergl",mode="markers", x=rnorm(10*N), y=rnorm(10*N))
  })
  output$p <- renderPlotly({
    plot_ly(type="scattergl",mode="markers", x=rnorm(N), y=rnorm(N))
  })
  output$p2 <- renderPlotly({
    plot_ly(type="scatter",mode="markers", x=rnorm(N), y=rnorm(N))
  })
  output$p3 <- renderPlotly({
    ggplotly(ggplot(data.frame(x=rnorm(N), y=rnorm(N)))+geom_point(aes(x=x,y=y)))
  })
  output$p3_ <- renderPlotly({
    ggplotly(ggplot(data.frame(x=rnorm(N), y=rnorm(N)))+geom_point(aes(x=x,y=y)), type="scattergl")
  })
}

shinyApp(ui, server, options = list(launch.browser=TRUE))

p、p10和p100的响应性还可以,其他的则不行。type="scattergl"似乎没有改变任何东西,据我所知。
我得到的输出

Listening on http://127.0.0.1:4932
Warning: 'scattergl' trace types don't currently render in RStudio on Windows. Open in another web browser (IE, Chrome, Firefox, etc).
Warning: 'scattergl' trace types don't currently render in RStudio on Windows. Open in another web browser (IE, Chrome, Firefox, etc).
Warning: 'scattergl' trace types don't currently render in RStudio on Windows. Open in another web browser (IE, Chrome, Firefox, etc).
Warning: 'scattergl' trace types don't currently render in RStudio on Windows. Open in another web browser (IE, Chrome, Firefox, etc).
Warning: 'scattergl' trace types don't currently render in RStudio on Windows. Open in another web browser (IE, Chrome, Firefox, etc).
Warning: 'scattergl' trace types don't currently render in RStudio on Windows. Open in another web browser (IE, Chrome, Firefox, etc).

我觉得这很奇怪,我在Firefox中打开了闪亮的应用程序,它也显示得很好,所以我不明白为什么我会收到这个警告。
总结一下我的问题:有没有办法让ggplotly的性能稍微好一点?

rekjcdws

rekjcdws1#

toWebGL(ggplot(data.frame(x=rnorm(N), y=rnorm(N)))+geom_point(aes(x=x,y=y)))似乎可以做到这一点。
唯一的缺点是,我得到了一吨的警告,很难静音。我会调查的

相关问题