-
Notifications
You must be signed in to change notification settings - Fork 157
/
Copy pathdisable-buttons.R
82 lines (71 loc) · 1.99 KB
/
disable-buttons.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
81
82
library(shiny)
library(shinyWidgets)
ui <- fluidPage(
theme = bslib::bs_theme(version = 5),
checkboxGroupButtons(
inputId = "check",
choices = setNames(1:6, head(month.name)),
label = "Check buttons"
),
radioGroupButtons(
inputId = "radio",
choices = setNames(1:6, head(month.name)),
label = "Radio buttons",
checkIcon = list(
yes = icon("square-check"),
no = icon("square")
)
),
tags$b("Check"),
verbatimTextOutput(outputId = "valCheck"),
tags$b("Radio"),
verbatimTextOutput(outputId = "valRadio"),
checkboxInput(inputId = "disable", label = "Disable?", value = FALSE),
checkboxInput(inputId = "disable1", label = "Disable march?", value = FALSE),
checkboxInput(inputId = "disable2", label = "Disable february & april?", value = FALSE)
)
server <- function(input, output, session) {
output$valCheck <- renderPrint({
input$check
})
output$valRadio <- renderPrint({
input$radio
})
observeEvent(input$disable, {
updateCheckboxGroupButtons(
session = session,
inputId = "check",
disabled = input$disable
)
updateRadioGroupButtons(
session = session,
inputId = "radio",
disabled = input$disable
)
}, ignoreInit = TRUE)
observeEvent(input$disable1, {
updateCheckboxGroupButtons(
session = session,
inputId = "check",
disabledChoices = if (input$disable1) 3 else NULL
)
updateRadioGroupButtons(
session = session,
inputId = "radio",
disabledChoices = if (input$disable1) 3 else NULL
)
}, ignoreInit = TRUE)
observeEvent(input$disable2, {
updateCheckboxGroupButtons(
session = session,
inputId = "check",
disabledChoices = if (input$disable2) c(2, 4) else NULL
)
updateRadioGroupButtons(
session = session,
inputId = "radio",
disabledChoices = if (input$disable2) c(2, 4) else NULL
)
}, ignoreInit = TRUE)
}
shinyApp(ui = ui, server = server, options = list(launch.browser = TRUE))