burgerga/shinyTime

0 to 9 with 2 digits

Closed this issue · 3 comments

This is not a issue at all. Maybe, it is just an idea for the future but, when I was using the package I saw that when the input (hour, minute or second) was between 0 and 9, one common time format was not being showed: instead of a 0 before the number, shinyTime shows only the number.

To clarify, instead of showing 06:05:00, the input shows 6:5:0

I tried to adapt a numericRangeInput from shinyWidgets in order to get something similar to timeInput from shinyTime and to solve this situation I had to change "hard-coding" an onchange parameter to add a 0 before the number when it was between 0 and 9.

I used something like this:

time_input_globo = function (inputId, label, value, width = NULL, separator = ":") 
{
value <- shiny::restoreInput(id = inputId, default = value)
value1 <- value[1]
value2 <- value[2]

value1 <- ifelse(is.null(value1),10,value1)
value2 <- ifelse(is.null(value2),0,value2)

fun_zero <- function(n){
  if(n<10){
    n <- paste('0',n,sep='')
  }else{
    n<- as.character(n)
  }
}

rangeTag <- htmltools::tags$div(id = inputId, class = "shiny-numeric-range-input form-group shiny-input-container", 
                                style = if (!is.null(width)) 
                                  paste0("width: ", htmltools::validateCssUnit(width), 
                                         ";"), shinyWidgets:::controlLabel(inputId, label), 
                                htmltools::tags$div(class = "input-numeric-range input-group",
                                                    htmltools::tags$input(type = "number", class = "form-control",
                                                                          min = "6", max = "29",
                                                                          value = fun_zero(value1)),
                                                    htmltools::tags$span(class = "input-group-addon",separator),
                                                    htmltools::tags$input(type = "number",class = "form-control",
                                                                          min = "0", max = "59",
                                                                          value = fun_zero(value2))))

rangeTag$children[[2]]$children[[1]]$attribs$onchange = "if(parseInt(this.value,10)<10)this.value='0'+parseInt(this.value,10);"
rangeTag$children[[2]]$children[[3]]$attribs$onchange = "if(parseInt(this.value,10)<10)this.value='0'+parseInt(this.value,10);"
shinyWidgets:::attachShinyWidgetsDep(rangeTag)}

Is https://burgerga.shinyapps.io/shinyTimeExample/ what you want? Because then we're looking at browser compatibility issue again 😔

I tested again and its working fine.. I think that this issue maybe was solved with the changes from the last issue.

Thanks for all the help

Happy to hear! I will try to prepare an update for CRAN soon. Thanks for taking the time to report these issues!