平滑过渡 renderPlot 闪亮 R

Jon*_*gra 5 rendering r shiny

我使用这种方法在 Shiny 中做了一个动画 我发现的问题是从情节到情节的过渡有点卡住(处理下一个情节时情节区域逐渐消失)。

我想保留之前的情节,直到下一个准备好。有没有办法从一个渲染图过渡到下一个渲染图,避免对先前图的淡化效果?

下面我包括一个最小的工作示例。如果您的计算机没有卡住,只需增加 K,它最终就会卡住。

library(shiny)
library(ggplot2)
k<-50000L
data=data.frame(x=runif(k),y=runif(k))

runApp(list(
  ui =fluidPage(
    tags$head(tags$style(".rightAlign{float:right;}")),
    headerPanel("Cost Explorer"),

    sidebarPanel(
      actionButton("goButton", "Go!"),
      actionButton("reset", "Reset")  ),
      mainPanel(fluidRow(column(8,
      plotOutput(outputId="tsplot"),class = 'rightAlign')))),

  server=function(input, output, session) {

  datareactive<-reactiveValues(data=data)
  t <- reactiveValues(counter=1)

  observe({
    isolate({   
      t$counter=t$counter+1;
      datareactive$data<-data.frame(x=runif(k),y=runif(k))
    })
      if ((input$goButton > 0)){
        invalidateLater(200, session)
      }



  })

    output$tsplot <- renderPlot({
      ggplot(datareactive$data,aes(x,y))+geom_point()+coord_fixed()+
      theme_bw()+
      geom_path(data=datareactive$data[(k-10):k,],aes(x,y),size=1.1,
                colour="blue")+
      geom_point(data=datareactive$data[k,],aes(x,y),
                   colour="red")
    })

  }
))
Run Code Online (Sandbox Code Playgroud)

Bas*_*era 0

您可以通过shinycssloaders在闪亮的 UI 中使用该包来完成此操作,如下所示:

plotOutput("tsplot") %>% shinycssloaders::withSpinner(hide.ui = FALSE)
Run Code Online (Sandbox Code Playgroud)

使用该参数hide.ui将避免绘图在加载时褪色。