updateAmGaugeChart: Update the score of a gauge chart

View source: R/shiny.R

updateAmGaugeChartR Documentation

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 documentation built on Sept. 22, 2022, 5:05 p.m.