@@ -84,9 +84,6 @@ reset <- function(id = "", asis = FALSE) {
8484 lapply(
8585 names(messages ),
8686 function (x ) {
87- type <- messages [[x ]][[' type' ]]
88- value <- messages [[x ]][[' value' ]]
89-
9087 # Make sure reset works with namespacing (shiny modules)
9188 id <- x
9289 if (substring(id , 1 , nchar(nsName )) == nsName ) {
@@ -100,11 +97,13 @@ reset <- function(id = "", asis = FALSE) {
10097 }
10198 funcParams <- list (session_to_reset , id )
10299
100+ type <- messages [[x ]][[' type' ]]
101+ value <- messages [[x ]][[' value' ]]
102+
103103 # checkbox values need to be manually converted to TRUE/FALSE
104104 if (type == " Checkbox" ) {
105105 value <- as.logical(value )
106106 }
107-
108107 if (type == " Date" ) {
109108 if (value == " NA" ) {
110109 value <- NA
@@ -144,16 +143,7 @@ reset <- function(id = "", asis = FALSE) {
144143 funcParams [[' value' ]] <- value
145144 }
146145
147- updateFunc <- sprintf(" update%sInput" , type )
148-
149- # radio buttons don't follow the regular shiny input naming conventions
150- if (type == " RadioButtons" ) {
151- updateFunc <- sprintf(" update%s" , type )
152- }
153- # for colour inputs, need to use the colourpicker package
154- else if (type == " Colour" ) {
155- updateFunc <- utils :: getFromNamespace(updateFunc , " colourpicker" )
156- }
146+ updateFunc <- getUpdateFunc(type )
157147
158148 # update the input to its original values
159149 do.call(updateFunc , funcParams )
@@ -163,3 +153,22 @@ reset <- function(id = "", asis = FALSE) {
163153
164154 invisible (NULL )
165155}
156+
157+ getUpdateFunc <- function (type ) {
158+ updateFunc <- sprintf(" update%sInput" , type )
159+ updateFuncAlt <- sprintf(" update%s" , type )
160+ pkg <- " "
161+
162+ if (type == " RadioButtons" ) {
163+ updateFunc <- updateFuncAlt
164+ }
165+ else if (type == " Colour" ) {
166+ pkg <- " colourpicker"
167+ }
168+
169+ if (pkg != " " ) {
170+ updateFunc <- utils :: getFromNamespace(updateFunc , pkg )
171+ }
172+
173+ updateFunc
174+ }
0 commit comments