Skip to content

Instantly share code, notes, and snippets.

@xiaodaigh
Last active August 18, 2022 17:45
Show Gist options
  • Save xiaodaigh/6810928 to your computer and use it in GitHub Desktop.
Save xiaodaigh/6810928 to your computer and use it in GitHub Desktop.
Shiny: Disable Button
library(shiny)
disableActionButton <- function(id,session) {
session$sendCustomMessage(type="jsCode",
list(code= paste("$('#",id,"').prop('disabled',true)"
,sep="")))
}
shinyServer(function(input, output,session) {
observe({
if(input$btn1 == 0) return()
disableActionButton("btn2",session)
})
})
library(shiny)
shinyUI(basicPage(
tags$head(tags$script(HTML('
Shiny.addCustomMessageHandler("jsCode",
function(message) {
console.log(message)
eval(message.code);
}
);
')))
,actionButton("btn1","Disable the other button")
,actionButton("btn2","Button")
)
)
@vitallish
Copy link

Hi, unfortunately the last comment didn't work for me. It should be as below - the property to change is still the 'disabled' property

enableActionButton <- function(id,session) {
  session$sendCustomMessage(type="jsCode",
                             list(code= paste("$('#",id,"').prop('disabled',false)"
                                    ,sep="")))
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment