Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trafficonese/e0c695d617f412ff31ead9688ba6b80a to your computer and use it in GitHub Desktop.
Save trafficonese/e0c695d617f412ff31ead9688ba6b80a to your computer and use it in GitHub Desktop.
actionButton change color/icon
library(shiny)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
sliderInput("slide","", 1,100,1,1),
actionButton("act", "Init label", icon = icon("check"), width = "300px")
)
server <- function(input, output, session) {
observe({
if (input$slide < 30) {
icon = "play-circle"
col = "red"
} else if (input$slide < 50) {
icon = "alipay"
col = "orange"
} else if (input$slide < 70) {
icon = "ad"
col = "yellow"
} else if (input$slide < 90) {
icon = "angle-down"
col = "green"
} else {
icon = "arrow-up"
col = "darkgreen"
}
updateActionButton(session, "act", label = col, icon = icon(icon))
runjs(
paste0("$('#act').css({'background-color': '",col,"', 'color': 'white'})")
)
})
}
shinyApp(ui, server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment