Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

updateAmGaugeChart

Update the score of a gauge chart


Description

Update the score of a gauge chart in a Shiny app

Usage

updateAmGaugeChart(session, outputId, score)

Arguments

session

the Shiny session object

outputId

the output id passed on to amChart4Output

score

new value of the score

Examples

library(rAmCharts4)
library(shiny)

gradingData <- data.frame(
  label = c("Slow", "Moderate", "Fast"),
  lowScore = c(0, 100/3, 200/3),
  highScore = c(100/3, 200/3, 100)
)


ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      sliderInput(
        "slider", "Score", min = 0, max = 100, value = 30
      )
    ),
    mainPanel(
      amChart4Output("gauge", height = "500px")
    )
  )
)

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

  output[["gauge"]] <- renderAmChart4({
    amGaugeChart(
      score = isolate(input[["slider"]]),
      minScore = 0, maxScore = 100, gradingData = gradingData,
      theme = "dataviz"
    )
  })

  observeEvent(input[["slider"]], {
    updateAmGaugeChart(session, "gauge", score = input[["slider"]])
  })

}

if(interactive()){
  shinyApp(ui, server)
}

rAmCharts4

Interface to the JavaScript Library 'amCharts 4'

v1.3.1
GPL-3
Authors
Stéphane Laurent [aut, cre], Antanas Marcelionis [ctb, cph] ('amCharts' library (https://www.amcharts.com/)), Terence Eden [ctb, cph] ('SuperTinyIcons' library (https://github.com/edent/SuperTinyIcons/)), Tom Alexander [ctb, cph] ('regression-js' library (https://github.com/Tom-Alexander/regression-js))
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.