Shiny: how to start application with action button disabled?

Viewed 123

I need to start an application with "button2" disabled. It should only be enabled after "button1" is pressed. How can I do this?

I'm trying to use enable/disable from the shinyjs package.

I can enable "button2" after pressing "button1", but how do I start the application with "button2" disabled?

     observeEvent(input$b1,{
        shinyjs::enable("b2")
        ... 
     })
1 Answers

You could use disabled in the UI definition :

library(shinyjs)
ui = fluidPage(
      useShinyjs(),  # Set up shinyjs
      disabled(actionButton("b2", "Click me")),
      ...
    )

Another option is to follow Hadley's answer:

ui = fluidPage(
      useShinyjs(),  # Set up shinyjs
      actionButton("b2", "Click me",disabled=''),
      ...
    )

To reactivate the button, shinyjs::enable works on both options

Related