-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmodule_checkbox_observe.R
80 lines (76 loc) · 2.64 KB
/
module_checkbox_observe.R
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
library(shiny)
## Somehow I am not using updateCheckboxGroupInput() correctly.
## The `Flip checks` checkboxInputs are supposed to do the following
## based on an steps in an observe():
## 1. Reset the checkbox for that `Flip checks` to FALSE.
## 2. Flip the `Check one` checkbox (TRUE to FALSE or FALSE to TRUE)
## 3. Select 1:2 for `Check group` and unselect 3:5.
## None of the three `Flip checks` accomplishes task 3.
## They each set selected to NULL for the checkboxGroupInput.
## `Flip checks 1` accomplishes task 1 & 2 only.
## `Flip checks 2` accomplishes taks 1 only.
## `Flip checks 3` accomplishes none of the tasks.
## The only difference is order placement in observe() of updateCheckboxGroupInput().
## Thanks for any feedback. [email protected].
checkboxGroupUI <- function(id) {
ns <- NS(id)
tagList(
checkboxInput(ns("check"), "Flip checks 1", FALSE),
checkboxInput(ns("check2"), "Flip checks 2", FALSE),
checkboxInput(ns("check3"), "Flip checks 3", FALSE),
uiOutput(ns("check_one")),
uiOutput(ns("check_group"))
)
}
checkboxGroup <- function(input, output, session) {
ns <- session$ns
output$check_group <- renderUI({
checkboxGroupInput(ns("ckgp"), "Check group", choices=1:5, inline=TRUE)
})
output$check_one <- renderUI({
checkboxInput(ns("ck1"), "Check one", FALSE)
})
observe({
check <- req(input$check)
if(check) {
updateCheckboxInput(session, "check", value=FALSE)
updateCheckboxInput(session, "ck1", value=!input$ck1)
updateCheckboxGroupInput(session, "ckgp", selected=1:2, choices=1:5,
inline=TRUE)
}
})
observeEvent(input$ckgp, {
browser()
select <- input$ckgp
not_select <- (1:5)[-select]
choice <- c(select,not_select)
updateCheckboxGroupInput(session, "ckgp", selected=select,
choices=choice,
inline=TRUE)
})
observe({
check2 <- req(input$check2)
if(check2) {
updateCheckboxInput(session, "check2", value=FALSE)
updateCheckboxGroupInput(session, "ckgp", selected=1:2, choices=1:5,
inline=TRUE)
updateCheckboxInput(session, "ck1", value=!input$ck1)
}
})
observe({
check3 <- req(input$check3)
if(check3) {
updateCheckboxGroupInput(session, "ckgp", selected=1:2, choices=1:5,
inline=TRUE)
updateCheckboxInput(session, "check3", value=FALSE)
updateCheckboxInput(session, "ck1", value=!input$ck1)
}
})
}
ui <- fluidPage(
checkboxGroupUI("module")
)
server <- function(input, output) {
callModule(checkboxGroup, "module")
}
shinyApp(ui, server)