Description Usage Arguments Details Value Examples
These functions allow you to observe multiple reactive elements based on their names
1 2 3 4 5 6 7 | observe_contains(match, handlerExpr, input, ignore.case = TRUE)
observe_starts_with(match, handlerExpr, input, ignore.case = TRUE)
observe_ends_with(match, handlerExpr, input, ignore.case = TRUE)
observe_one_of(elements, handlerExpr, input, ignore.case = TRUE)
|
match |
character |
handlerExpr |
The expression to call whenever |
input |
reactive object to observe |
ignore.case |
logical If TRUE ignores case when matching names, Default: TRUE |
elements |
character vector contains names of elements in the reactive object |
The internal shiny:observeEvent is passed a variable var_
that contains the matched element name in the reactive object input. That variable
can be defined as a paramter of handlerExpr.
observer reference class object
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | ## Not run:
if(interactive()){
ui <- shiny::fluidPage(
shiny::column(width = 6,
lapply(1:4,FUN = function(x){
shiny::textInput(inputId = sprintf('txt_%02d',x),
label = NULL,
value = '',
placeholder = letters[x])
})),
shiny::column(width = 6,
lapply(1:4,FUN = function(x){
shiny::actionButton(inputId = sprintf('btn_%02d',x),label = 'update')
})
)
)
server <- shiny::shinyServer(function(input, output,session) {
shinyselect::observe_contains('btn_0(1|3)',
handlerExpr = function(var_){
shiny::updateTextInput(
session,
inputId = gsub('btn','txt',var_),
value = strrep(letters[as.numeric(gsub('[^0-9]','',var_))],3)
)
},input)
shinyselect::observe_one_of(c('btn_02','btn_04'),
handlerExpr = function(var_){
shiny::updateTextInput(
session,
inputId = gsub('btn','txt',var_),
placeholder = 'something new'
)
},input)
})
shiny::shinyApp(ui = ui, server = server)
}
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.