user8248672
user8248672

Reputation:

Display incrementing numbers from 0 to value in shiny infoBox

I have a infoBox here:

enter image description here

When I load this box, I'd like to visualize these numbers (7659 and 65.3%) by incrementing numbers from 0. Please see this Javascript demo for a great example of what I want, but in shiny: https://jsfiddle.net/NevilPaul2/LLk0bzvm/

Does anyone know of a function for shiny similar to this?

Upvotes: 1

Views: 244

Answers (1)

SBista
SBista

Reputation: 7704

You can do that invalidateLater function. Here is an example code:

library(shiny)
library(shinydashboard)

header <- dashboardHeader()

sidebar <- dashboardSidebar()

body <- dashboardBody(
  infoBoxOutput("ibox"),
)

ui <- dashboardPage(header, sidebar, body)
server <- function(input, output, session){

  val <- reactiveVal(0)

  output$ibox <- renderInfoBox({
    infoBox(
      "Number",
      val(),
      icon = icon("credit-card")
    )
  })
  observe({
    invalidateLater(100, session)
    isolate({
# It will count till 5000 because of this condition
      if(val() < 5000) {
        newVal <- val()+1
        val(newVal)
      }
    })
  })
}
shinyApp(ui, server)

Hope it helps!

Upvotes: 2

Related Questions