Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yonicd/shinyselect
Observe Multiple Reactive Elements using tidyselect-like verbs
https://github.com/yonicd/shinyselect
Last synced: 2 months ago
JSON representation
Observe Multiple Reactive Elements using tidyselect-like verbs
- Host: GitHub
- URL: https://github.com/yonicd/shinyselect
- Owner: yonicd
- License: other
- Created: 2019-08-26T19:53:12.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-08-27T13:35:09.000Z (over 5 years ago)
- Last Synced: 2024-08-13T07:15:34.891Z (4 months ago)
- Language: R
- Size: 11.7 KB
- Stars: 12
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - yonicd/shinyselect - Observe Multiple Reactive Elements using tidyselect-like verbs (R)
README
# shinyselect
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
The goal of shinyselect is to use tidyselect-like verbs when applying an [observeEvent or eventReactive](https://shiny.rstudio.com/reference/shiny/1.0.3/observeEvent.html) handler function to multiple elements
## Installation
``` r
remotes::install_github("yonicd/shinyselect")
```Functions that are defined are
- `Observe`
- `observe_contains`: Contains a literal string matched to elements names in a reactive object.
- `observe_starts_with`: Starts with a prefix that are matched to elements names in a reactive object.
- `observe_ends_with`: Ends with a suffix that are matched to elements names in a reactive object.
- `observe_one_of`: Matches elements names in a reactive object.- `Reactive`
- `reactive_contains`: Contains a literal string matched to elements names in a reactive object.
- `reactive_starts_with`: Starts with a prefix that are matched to elements names in a reactive object.
- `reactive_ends_with`: Ends with a suffix that are matched to elements names in a reactive object.
- `reactive_one_of`: Matches elements names in a reactive object.## Example
This is a basic example which shows you how to solve a common problem:
## Observe
``` r
library(shinyselect)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)
```
## Reactive
```r
ui <- shiny::fluidPage(
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) {
out <- shinyselect::reactive_one_of(c('btn_01','btn_03'),valueExpr = function(var_){
runif(as.numeric(gsub('[^0-9]','',var_)))
},input)shinyselect::observe_contains(match = 'btn_0(1|3)',
handlerExpr = function(var_){
print(out()[[var_]]())
},
input = out()
)})
shiny::shinyApp(ui = ui, server = server)
```