Home > Blockchain >  How to reset label of flexdashboard gauges in Shiny?
How to reset label of flexdashboard gauges in Shiny?

Time:02-16

I would like to have different labels for gauges created using the flexdashboard package depending on the selection that is made. However, when a new option is chosen the first label that is loaded remains but the input updates. Is there some way to clear the cache so that the labels will change?

Below is a reprex of the problem in Shiny:

library(shiny)
library(flexdashboard)

ui <- fluidPage(

  sidebarLayout(
    sidebarPanel(
      radioButtons("labelChoice",
                   label = "Choose a label",
                   choices = c("Label 1", "Label 2")
      )
    ),
    
    mainPanel(
      gaugeOutput("gauges")
    )
  )
)

server <- function(input, output) {
  
  observe({
    
    if(input[["labelChoice"]] == "Label 1") {
      output$gauges <- renderGauge({ gauge(15, min = 0, max = 100, label = "Hello I'm label 1!") })
    } else {
      output$gauges <- renderGauge({ gauge(55, min = 0, max = 100, label = "Hello I'm label 2!") })
    }
    
  })
  
}

# Run the application 
shinyApp(ui = ui, server = server)

CodePudding user response:

Reactive objects need HTML tags of class shiny-bound-input. The flexdashboard gauge, however, usually creates a svg which is out of the scope of shiny's reactive context.

This is fixed with a newer version (see this issue on 20th Sep 2021). Try to update using remotes::install_github("rstudio/flexdashboard").

  • Related