Created
July 4, 2019 12:16
-
-
Save trafficonese/e0c695d617f412ff31ead9688ba6b80a to your computer and use it in GitHub Desktop.
actionButton change color/icon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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