Isn't disabled
from library(shinyjs)
an option for you?
It appends the disabled attribute while the UI is rendered:
tags[[1]] <- shiny::tagAppendAttributes(tags[[1]], class = "shinyjs-disabled")
It can also be applied in renderUI
:
library(shiny)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
uiOutput("myDisabledUI"),
uiOutput("myHiddenUI")
)
server <- function(input, output, session) {
output$myDisabledUI <- renderUI({
disabled(tagList(
p("Disabled:"),
actionButton("testBtn", "testBtn"),
textInput("testInput", "testInput")
))
})
output$myHiddenUI <- renderUI({
hidden(tagList(
p("We won't be displayed:"),
actionButton("testBtn2", "testBtn2"),
textInput("testInput2", "testInput2")
))
})
}
shinyApp(ui, server)