EVOLUTION-MANAGER
Edit File: stateFuncs.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Enable/disable an input element</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for stateFuncs {shinyjs}"><tr><td>stateFuncs {shinyjs}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Enable/disable an input element</h2> <h3>Description</h3> <p>Enable or disable an input element. A disabled element is not usable and not clickable, while an enabled element (default) can receive user input. Any shiny input tag can be used with these functions.<br /><br /> <strong><code>enable</code></strong> enables an input, <strong><code>disable</code></strong> disabled an input,<strong><code>toggleState</code></strong> enables an input if it is disabled and disables an input if it is already enabled.<br /><br /> If <code>condition</code> is given to <code>toggleState</code>, that condition will be used to determine if to enable or disable the input. The element will be enabled if the condition evaluates to <code>TRUE</code> and disabled otherwise. If you find yourself writing code such as <code>if (test()) enable(id) else disable(id)</code> then you can use <code>toggleState</code> instead: <code>toggleState(id, test())</code>. </p> <h3>Usage</h3> <pre> enable(id = NULL, selector = NULL, asis = FALSE) disable(id = NULL, selector = NULL, asis = FALSE) toggleState(id = NULL, condition = NULL, selector = NULL, asis = FALSE) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>id</code></td> <td> <p>The id of the input element/Shiny tag</p> </td></tr> <tr valign="top"><td><code>selector</code></td> <td> <p>Query selector of the elements to target. Ignored if the <code>id</code> argument is given. For example, to disable all text inputs, use <code>selector = "input[type='text']"</code></p> </td></tr> <tr valign="top"><td><code>asis</code></td> <td> <p>If <code>TRUE</code>, use the ID as-is even when inside a module (instead of adding the namespace prefix to the ID).</p> </td></tr> <tr valign="top"><td><code>condition</code></td> <td> <p>An optional argument to <code>toggleState</code>. The element will be enabled when the <code>condition</code> is <code>TRUE</code>, and disabled otherwise.</p> </td></tr> </table> <h3>Note</h3> <p><code>shinyjs</code> must be initialized with a call to <code>useShinyjs()</code> in the app's ui. </p> <h3>See Also</h3> <p><code><a href="useShinyjs.html">useShinyjs</a></code>, <code><a href="runExample.html">runExample</a></code> <code><a href="disabled.html">disabled</a></code> </p> <h3>Examples</h3> <pre> if (interactive()) { library(shiny) shinyApp( ui = fluidPage( useShinyjs(), # Set up shinyjs actionButton("btn", "Click me"), textInput("element", "Watch what happens to me") ), server = function(input, output) { observeEvent(input$btn, { # Change the following line for more examples toggleState("element") }) } ) } ## Not run: # The shinyjs function call in the above app can be replaced by # any of the following examples to produce similar Shiny apps toggleState(id = "element") enable("element") disable("element") # Similarly, the "element" text input can be changed to many other # input tags, such as the following examples actionButton("element", "I'm a button") fileInput("element", "Choose a file") selectInput("element", "I'm a select box", 1:10) ## End(Not run) ## toggleState can be given an optional `condition` argument, which ## determines if to enable or disable the input if (interactive()) { shinyApp( ui = fluidPage( useShinyjs(), textInput("text", "Please type at least 3 characters"), actionButton("element", "Submit") ), server = function(input, output) { observe({ toggleState(id = "element", condition = nchar(input$text) >= 3) }) } ) } </pre> <hr /><div style="text-align: center;">[Package <em>shinyjs</em> version 2.1.0 <a href="00Index.html">Index</a>]</div> </body></html>