-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.R
45 lines (35 loc) · 1.21 KB
/
functions.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
get_var_value_list <- function(value_labels = codebook_2023, var_name){
val_list <- value_labels %>% filter(variable == var_name) %>%
rowwise() %>%
mutate(value_label = paste0(value, ": ", final_label)) %>%
ungroup() %>%
select(value, value_label)
return(setNames(as.list(val_list$value), nm = val_list$value_label))
}
# dropdown for single selection
selectInputSingle <- function(df, var_name, label_name = NULL, ...) {
if(is.null(label_name)){
label_name = var_name
}
selectInput(inputId = paste0("select_",var_name),
label = label_name,
choices = get_var_value_list(var_name=var_name),
selected = df[1,c(var_name)],
selectize = TRUE,
...)
}
textInputSimple <- function(df, var_name, ...){
textInput(inputId = paste0("textinput_",var_name),
label = var_name,
value = df[1,c(var_name)],
...)
}
numericInputSimple <- function(df, var_name, label_name = NULL, ...){
if(is.null(label_name)){
label_name = var_name
}
numericInput(inputId = paste0("numinput_",var_name),
label = label_name,
value = df[1,c(var_name)],
...)
}