0

I'm having trouble disabling and enabling actionButton in Shiny Modules. I created a simple app to visualize my problem. The application contains 3 actionButtons.

  1. the first button does nothing, it's just a button that we'll want to toggle on/off
  2. the second one called enable is used to enable the button
  3. the last one, called disable, is used to disable the button

Code below:

library(shiny)

moduleUI <- function(id){
  ns <- NS(id)
  fluidRow(
    column(4, uiOutput(ns("button"))),
    column(4, uiOutput(ns("enable"))),
    column(4, uiOutput(ns("disable")))
  )
}
moduleServer <- function(input, output, session){
  ns <- session$ns
  
  observeEvent(input$disable_id, {
    shinyjs::disable("button_id")
    shinyjs::disable("disable_id")
  })
  observeEvent(input$disable_id, {
    shinyjs::enable("button_id")
    shinyjs::enable("enable_id")
  })
  
  output$button  <- renderUI({
    actionButton(ns("button_id"), "button")
  })
  output$enable  <- renderUI({
    actionButton(ns("enable_id"), "enable")
  })
  output$disable <- renderUI({
    actionButton(ns("disable_id"), "disable")
  })
}

ui     <- fluidPage(moduleUI("module_id"))
server <- function(input, output) {callModule(moduleServer, "module_id")}

shinyApp(ui, server)

Where is a bug in that code?

tomsu
  • 371
  • 2
  • 16

0 Answers0