r - Disable textInput based on radio button selection on Shiny -


say have following shiny app:

library(shiny) ui <- fluidpage(   column(3,          radiobuttons("radios", "",                       c("enabled" = "enabled",                         "disabled" = "disabled"),                       inline = true)   ),   column(4, textinput("text", "", value = "disable me")) ) server <- function(input, output) {  } shinyapp(ui=ui, server=server) 

what's easiest way disable textinput based on selected radio button? know have add ... disabled /> input tag, have no idea on how in shiny.

i tried building full tag "manually" pasting html string, selected radio value , rest of html, using uioutput , renderui (based on this), didn't work.

the textinputgenerates this:

<input id="text" type="text" class="form-control" value="disable me"/> 

and need able switch between above , this:

<input id="text" type="text" class="form-control" value="disable me" disabled /> 

you session$sendcustommessage on server (which generates javascript disables or enables text box) , shiny.addcustommessagehandler in ui (which executes javascript).

library(shiny) ui <- fluidpage(   tags$head(tags$script(html('       shiny.addcustommessagehandler("jscode",         function(message) {           eval(message.code);         }       );     '))),   column(3,          radiobuttons("radios", "",                       c("enabled" = "enabled",                         "disabled" = "disabled"),                       inline = true)   ),   column(4, textinput("text", "", value = "disable me")) ) server <- function(input, output, session) {   observe({     if(input$radios == "disabled") {       session$sendcustommessage(type="jscode",                                 list(code= "$('#text').prop('disabled',true)"))     } else {       session$sendcustommessage(type="jscode",                                 list(code= "$('#text').prop('disabled',false)"))     }   }) } shinyapp(ui=ui, server=server) 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -