Search code examples
shinyaction-button

Hiding button A on click of button B in Shiny


Very simple question: In my shiny UI, I have two buttons, A and B

on the click of button B I would like button A to be hidden, but I don't think updateActionButton has this capability. So how is this accomplished?

Thanks in advance


Solution

  • Dean built wonderful shinyjs package that has this functionality. Note that I added toggle instead of hide but you can switch if you like

    rm(list = ls())
    library(shiny)
    library(shinyjs)
    
    ui <- fluidPage(
      useShinyjs(),
      actionButton("hide","a"),
      actionButton("b","b")
    )
    
    server <- shinyServer(function(input,output){
    
      observeEvent(input$hide,{
        toggle("b")
      })
    
    })
    runApp(list(ui = ui, server = server))
    

    enter image description here