Some element (like div) can get class attribute and some (actionButton) doesn't.
It depends on element that you want to create
for actionButton. if you look shiny's default actionButton.
it will not allow to insert style attributes.
since only width attribute will be applied ( Line4 ).
so in this case, you have to "re-define" this actionButton with accepts style attributes.
for example, I usually re-define myButton like this.
- added
disabled parameter to apply on actionButton's class. refer this link
- removed
validateIcon term in Line7, this function does not work outside shiny I think.
myButton <- function(inputId, label, icon = NULL, width = NULL, disabled = FALSE, ...) {
value <- restoreInput(id = inputId, default = NULL)
class <- "btn btn-default action-button"
tags$button(
id = inputId,
style = if (!is.null(width)) paste0("width: ", validateCssUnit(width), ";"),
type = "button",
class = if (disabled) paste0(class, " disabled"),
`data-val` = value, list(icon, label),
...
)
}
you can check myButton via this code.
ui <- fluidPage(
myButton("btnA", "BTNA", disabled = TRUE),
myButton("btnB", "BTNB", disabled = FALSE)
)
server <- function(input, output, session) {
}
shinyApp(ui, server)

Regards.