Skip to content

Instantly share code, notes, and snippets.

@XD-DENG
Forked from xiaodaigh/server.R
Created March 19, 2016 04:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save XD-DENG/1e31e690237794f45744 to your computer and use it in GitHub Desktop.
Save XD-DENG/1e31e690237794f45744 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")
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment