Learn R Programming

rAmCharts4 (version 1.6.0)

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

Run this code
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)
}

Run the code above in your browser using DataLab