1

I need to refresh data displayed in an infobox on a regular interval, but every time it updates it renders a new infobox making for an undesirable user experience.

I've tried using futures/promises for async processing but the renderinfobox still renders a new box on data update. Here's my code :

invalidateLater(30000)
results <-future({testFuture()})
return(value(results))

I would like to be able to update the underlying data of the infobox without dimming the ui element for the entire duration of the query.

Gainz
  • 1,721
  • 9
  • 24
davesauto
  • 83
  • 4
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Sep 12 '19 at 15:24
  • I don't have a reproducible example that I can share. As in I connect to a database to run a query to update the infobox. The problem I am having is when I run an aync query the infobox renders during the entire query, causing a not so desirable user experience. Someone with experience with renderinfobox will know exactly what I'm talking about. – davesauto Sep 12 '19 at 16:12
  • `output$example <- renderInfoBox({` `values <- future({exampleFunction})infoBox("example box", value = prettyNum(as.numeric(values[1]),big.mark = ","), subtitle = HTML(paste(values[-1], collapse = '
    ')), icon = icon("server"), color = 'blue')` `})`
    – davesauto Sep 12 '19 at 16:20

1 Answers1

0

Instead of re-rendering the infobox everytime the value changes, you can re-render just the title or the value of the infobox as I have shown by creating an output element. I have created an working example that refreshes the infobox to show current time at seconds level.

library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(title = "Test App"),
  dashboardSidebar(),
  dashboardBody(
    infoBox("TestBox", value = textOutput("currentTime"), subtitle = NULL,
            icon = shiny::icon("bar-chart"), color = "aqua", width = 4,
            href = NULL, fill = FALSE)
  )
)

server <- function(input, output, session) {

  output$currentTime <- renderText({
    invalidateLater(1000, session)
    paste(Sys.time())
  })

}

shinyApp(ui = ui, server = server)

Do try out your code with this and let me know if this helps!

FAlonso
  • 494
  • 2
  • 15