5

I am updating a text output in shiny every second which is read from a sql database and it just takes some time. In the dashboard I just want to see how the output changes without the fancy animation / flickering. Is there away to remove the animation and just display the text while it waits for the update?

Here is some Code Example in which you can see the flickering of the update:

# ui.R
library(shiny)

shinyUI(fluidPage(

  # App title ----
  titlePanel("Title"),

  # Sidebar layout with input and output definitions ----
  sidebarLayout(

    # Sidebar panel for inputs ----
    sidebarPanel(),

    # Main panel for displaying outputs ----
    mainPanel(
      # Output: Data file ----
      # Output: Tabset w/ plot, summary, and table ----
      tabsetPanel(type = "tabs",
                  tabPanel("Main", 
                           textOutput("foo"))
      )

    )
  )
)
)

# server.R
library(shiny)

check_for_update <- function() {
  Sys.time()
}
get_data <- function() {
  df <- data.frame(replicate(20000,sample(0:1000,rep=TRUE)))
}


shinyServer(
  function(input, output, session) {
    # checks for new data every 1 seconds
    data <- reactivePoll(50, session,
                         checkFunc = check_for_update,
                         valueFunc = get_data)

    # the outputs will only be refreshed in case the data changed
    output$foo <- renderText({
      df <- data()
      df[[2]]
    })
  }
)

Thanks in advance!

Blind0ne
  • 1,015
  • 12
  • 28

1 Answers1

1

The flickering/refresh can't be avoided with some html induced plots, such as through leaflet.

You can adjust the opacity to 1, of your shiny app to give off the illusion that it doesn't flicker, but it will only work for some non-html objects. See this link and the answer by Joe Cheng. I was never able to solve this issue a year and a half ago.

The flickering can be removed with animations of grob objects for example. Try Joe's solution with some animation with a ggplot line graph.

InfiniteFlash
  • 1,038
  • 1
  • 10
  • 22