@@ -61,9 +61,8 @@ data_extract_filter_srv <- function(id, datasets, filter) {
61
61
)
62
62
})
63
63
64
- output $ html_vals_container <- renderUI ({
64
+ vals_options <- reactive ({
65
65
req(input $ col )
66
-
67
66
choices <- value_choices(
68
67
data = datasets [[filter $ dataname ]](),
69
68
var_choices = input $ col ,
@@ -77,16 +76,38 @@ data_extract_filter_srv <- function(id, datasets, filter) {
77
76
} else {
78
77
choices [1L ]
79
78
}
79
+ selected <- restoreInput(ns(" vals" ), selected )
80
+ list (choices = choices , selected = selected )
81
+ })
80
82
83
+ output $ html_vals_container <- renderUI({
81
84
teal.widgets :: optionalSelectInput(
82
85
inputId = ns(" vals" ),
83
86
label = filter $ label ,
84
- choices = choices ,
85
- selected = selected ,
87
+ choices = vals_options() $ choices ,
88
+ selected = vals_options() $ selected ,
86
89
multiple = filter $ multiple ,
87
90
fixed = filter $ fixed
88
91
)
89
92
})
93
+
94
+ # Since we want the input$vals to depend on input$col for downstream calculations,
95
+ # we trigger reactivity by reassigning them. Otherwise, when input$col is changed without
96
+ # a change in input$val, the downstream computations will not be triggered.
97
+ observeEvent(input $ col , {
98
+ teal.widgets :: updateOptionalSelectInput(
99
+ session = session ,
100
+ inputId = " vals" ,
101
+ choices = " " ,
102
+ selected = " "
103
+ )
104
+ teal.widgets :: updateOptionalSelectInput(
105
+ session = session ,
106
+ inputId = " vals" ,
107
+ choices = vals_options()$ choices ,
108
+ selected = vals_options()$ selected
109
+ )
110
+ })
90
111
}
91
112
)
92
113
}
0 commit comments