@@ -269,7 +269,39 @@ updateNumericInput <- function(session, inputId, label = NULL, value = NULL,
269
269
# ' )
270
270
# ' }
271
271
# ' @export
272
- updateSliderInput <- updateNumericInput
272
+ updateSliderInput <- function (session , inputId , label = NULL , value = NULL ,
273
+ min = NULL , max = NULL , step = NULL )
274
+ {
275
+ # Make sure that value, min, max all have the same type, because we need
276
+ # special handling for dates and datetimes.
277
+ vals <- dropNulls(list (value , min , max ))
278
+
279
+ type <- unique(lapply(vals , function (x ) {
280
+ if (inherits(x , " Date" )) " date"
281
+ else if (inherits(x , " POSIXt" )) " datetime"
282
+ else " number"
283
+ }))
284
+ if (length(type ) > 1 ) {
285
+ stop(" Type mismatch for value, min, and max" )
286
+ }
287
+
288
+ if (type == " date" || type == " datetime" ) {
289
+ to_ms <- function (x ) 1000 * as.numeric(as.POSIXct(x ))
290
+ if (! is.null(min )) min <- to_ms(min )
291
+ if (! is.null(max )) max <- to_ms(max )
292
+ if (! is.null(value )) value <- to_ms(value )
293
+ }
294
+
295
+ message <- dropNulls(list (
296
+ label = label ,
297
+ value = formatNoSci(value ),
298
+ min = formatNoSci(min ),
299
+ max = formatNoSci(max ),
300
+ step = formatNoSci(step )
301
+ ))
302
+ session $ sendInputMessage(inputId , message )
303
+ }
304
+
273
305
274
306
updateInputOptions <- function (session , inputId , label = NULL , choices = NULL ,
275
307
selected = NULL , inline = FALSE ,
0 commit comments