#' Text Input module UI
#'
#' @description A text input module UI that has the flexibility to
#' be enabled and disabled based on actions that javascript will listen for
#'
#' @param id is unique ID associated with the \code{textInput} for the UI namespace
#'
#' @return HTML UI code for a shiny application
#' @importFrom shiny uiOutput
#' @export
text_ui <- function(id) {
ns <- NS(id)
uiOutput( ns("text"))
}
#' Text Input module Server
#'
#' @description A text input module server code that has the flexibility to
#' be enabled and disabled based on actions that javascript will listen for
#'
#' @param input list of inputs used in the shiny application session
#' @param output list of outputs used the shiny application session
#' @param session The shiny app session object
#' @param label a character describing the action button's use or purposes
#' @param width size of the \code{textInput}
#' @param placeholder placeholder ghost text in the \code{textInput}
#' @param updateVal A reactive function. The reactive function should return the value which is used to update the text
#' @param trig A reactive function. The reactive function should result in a logical value to trigger the enable or disable action
#' @param disable Logical. A logical value that enables the trigger actions
#'
#' @return character. Text Input value
#' @importFrom shinyjs enable disable
#' @importFrom shiny textInput
#' @importFrom shiny updateNumericInput
#' @export
text_server <-
function(input,
output,
session,
label = "Initiative Name:",
width = "100%",
placeholder = "What is the initiative called?",
updateVal = NA,
trig,
disable = T) {
session$ns -> ns
#Is the label a reactive function?
label_<-to_reactive(label)
output[['text']]<-renderUI({textInput(ns('text'),label_(),placeholder = placeholder)})
if (!missing("trig"))
observeEvent(trig(), ignoreInit = TRUE, {
updateNumericInput(session, "text", value = updateVal())
if (disable & trig())
disable(id = "text")
if(disable & !trig())
enable(id = "text")
})
return(list(text = reactive(input$text)))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.