'Smoothly transition renderPlot shiny R
I have done an animation in Shiny using this approach The problem I find is that the transition from plot to plot gets a bit stuck (The plot area fades off while processing the next plot).
I would like to keep the prior plot until the next is ready. Is there a way to transition from the one renderPlot to the next one avoiding the fade off effect on the prior plot?
Below I include a minimal working example. If your computer does not get stuck just increase the K and it eventually will.
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")
})
}
))
Solution 1:[1]
You can do this by using the shinycssloaders package in your shiny UI, like this:
plotOutput("tsplot") %>% shinycssloaders::withSpinner(hide.ui = FALSE)
Using the argument hide.ui will avoid the fading of the plot while its being loaded.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Bastián Olea Herrera |
