ReactiveTextInput: ReactiveTextInput

Description Usage Arguments Details Value See Also Examples

View source: R/ReactiveTextInput.R

Description

This is a reactive series of text input fields with a functionality for validating the provided text inputs. The number of text input fields in reactive.

Usage

1
2
ReactiveTextInput(input, output, session, n, prefix = "Input",
  values = NULL, dummies = NULL, checkFun = NULL, addArgs = NULL)

Arguments

input

argument used by shiny session

output

argument used by shiny session

session

argument used by shiny session

n

reactive int which controls the number of text input fields

prefix

chr or NULL ("Input") used as prefix for creating a label for each text input field. NULL for no labels

values

chr arr or NULL (NULL) for default values for each text input field. This is an actual input.

dummies

chr arr or NULL (NULL) for dummy text inside each text input field. This text is visible in each field but not an actual input.

checkFun

chr or NULL (NULL) if not NULL name of a function which can be used as a quality check for textInputs

addArgs

list or NULL (NULL) if not NULL list of additional arguments which will be passed to checkFun

Details

Arguments dummies and values can be NULL or a chr arr of >= 1. As n – the number of text input fields – increases dummies and values are being iterated (see example n >= 3).

With argument checkFun a function name can be defined which will be used as quality control for the text inputs. This function must take a chr arr as first argument. These are the user provided text inputs. The function must either return NULL or a chr value. NULL means the input is valid. Thereby the module returns this chr arr. If the user input should not be valid, the function must return a character value. This chr value will be rendered as a error message for the user, and the modul returns NULL.

Additional argumets can be handed over to checkFun via the list addArgs.

Value

chr arr of user provided text input fields or NULL

See Also

Other ReactiveTextInput module functions: ReactiveTextInputUI

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
library(shinyTools)

# some function as example
check <- function(text, add){ if(any(grepl(add$pat, text))) return(paste("Don't use letter", add$pat, "in any entry."))}

# little app with module
ui <- fluidPage(sidebarLayout(
  sidebarPanel(h2("ReactiveTextInputUI"),
               numericInput("nGroups", "n Groups", 2, -2, 10),
               ReactiveTextInputUI("id1", "Groups")
  ),
  mainPanel(h2("Output of ReactiveTextInput"), verbatimTextOutput("display"))
))


server <-function(input, output, session) {
  display <- callModule(ReactiveTextInput, "id1", n = reactive(input$nGroups), prefix = "Group",
                        values = c("Untreated", "Treated"), checkFun = "check", addArgs = list(pat = "X"))
  output$display <- renderPrint(display())
}

shinyApp(ui, server)

mRcSchwering/shinyTools documentation built on May 21, 2019, 10:14 a.m.