I have a shiny app with a bunch of tabs with a few plots on each. There is also a sidebar with some controls, and when I change the inputs the plots may take a couple of seconds to refresh. This is absolutely fine (the data needs to be loaded from the database).
What is less fine is that when I switch away from a tab and then return to it later, first couple of seconds I see the old version of the plots, which can be very confusing, especially in cases when delays reach 3-5 seconds (doesn't happen often, but I couldn't find a way to prevent it from happening altogether).
Any suggestions would be greatly appreciated.
Below please some code that hopefully helps illustrate the problem if it's not clear from the description. Switch the tabs, move the slider towards either end to change the graph, and then go back to the original tab -- you should be able to see the image switch from the old version to new which is the behavior I want to get rid of.
library(shiny)
ui <- fluidPage(
titlePanel("Old Faithful Geyser Data"),
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 5000,
value = 3000)
),
mainPanel(
tabsetPanel(
tabPanel("tab1",
plotOutput("distPlot1")
),
tabPanel("tab2",
plotOutput("distPlot2")
)
)
)
)
)
server <- function(input, output) {
output$distPlot1 <- renderPlot({
x <- rnorm(input$bins)
bins <- seq(min(x), max(x), length.out = input$bins + 1)
plot(1:input$bins, x)
})
output$distPlot2 <- renderPlot({
x <- rnorm(input$bins)
bins <- seq(min(x), max(x), length.out = input$bins + 1)
plot(1:input$bins, x)
})
}
shinyApp(ui = ui, server = server)