我用this approach制作了一个闪亮的动画。我发现的问题是,从绘图到绘图的转换有点卡住了(在处理下一个绘图时,绘图区域会逐渐消失)。
我想保留之前的情节,直到下一个准备好。是否有办法从一个renderPlot过渡到下一个renderPlot,以避免前一个情节的褪色效果?
下面我介绍了一个最小的工作示例。如果你的电脑没有卡住,只需增加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")
})
}
))发布于 2022-03-17 00:10:23
您可以通过在闪亮的UI中使用shinycssloaders包来做到这一点,如下所示:
plotOutput("tsplot") %>% shinycssloaders::withSpinner(hide.ui = FALSE)使用参数hide.ui将避免情节在加载时褪色。
https://stackoverflow.com/questions/42135683
复制相似问题