UI elements for selecting date and time (not just dates) in brilliant

In the past, I used a combination of dateInput and a slider to get the date and time for my brilliant app. I was wondering if there is now a better option, since I need to collect data up to a minute.

An Internet search did not help to ask SO.

thanks

+6
source share
3 answers

It was a long time ago, since this question was asked, but I assume that it remains relevant, since I could not find a satisfactory answer for obtaining temporary inputs.

Below are 3 examples for getting time input.

  • Firstly, I believe that most people, including me, have been or are looking. Shiny input time object for temporary input. It uses the HTML input time: <input id = 'ui_time' type = 'time'>, followed by a simple javascript function to retrieve the input data before moving on to the Shiny.onInputChange () function for passing as input to the Shiny server.

    <input id="ui_time" type="time">

    '<script> document.getElementById("ui_time").onchange = function() { var time = document.getElementById("ui_time").value; Shiny.onInputChange("input_html", time); }; </script>'

  • The second, which is probably not desirable, but adheres to the use of sliders, is a simple but cumbersome hack to create 2 sliders, one to record time, and the other to register minutes before concatenating two results, return the correct time entry.

    sliderInput("slider_hours", "Hours:", min=0, max=23, value=0, step = 1), sliderInput("slider_mins", "Mins:",min = 0, max = 59, value = 0, step = 1)

  • Finally, if date and time formats are required, some may not know how I didn’t, that the slider accepts date time data as POSIXt objects. In this case, the input of the slider can be constructed as follows:

    sliderInput("slider_datetime", "Date & Time:", min=as.POSIXlt("2010-01-01 00:00:00", "GMT"), max=as.POSIXlt("2020-01-01 23:59:59", "GMT"), value=as.POSIXlt("2010-01-01 00:00:00", "GMT"), timezone = "GMT")

For those less familiar with brilliant or html, you can view a functional code example in my github: https://github.com/krenova/Shiny_TimeInput/blob/master/app.R

or just run the following line in R:

runGist('https://gist.github.com/krenova/fc184de17892905182a422c96117e989')

I am new to brilliant and html, raised it only last week, so please keep in mind that I may not have done something in the most appropriate way. In any case, I hope this saves someone a few hours!

+4
source

I ran into the same problem and ended up creating a text box. I prefilled the text box to show users the correct format and added validation (using try to make sure the box was formatted correctly before doing anything.

From UI.R

 textInput("fromDatetime", "From:", value = "9999-99-99 99:99:99" ) 

And then in server.R

  fromDTtry = try(as.POSIXct(fromDatetime)) if (!(is.POSIXct(fromDTtry))) { return ("From date/time not formatted correctly") } else { ... } 

Hope this helps. Hopefully Shiny will soon start supporting the native date / time.

+3
source

Now you can use the shinyTime package for intuitive time entry in the Shiny App. At the moment, it works with separate numerical inputs, which together make up the time in the format %H:%M or %H:%M:%S Getting and setting a value in R is performed using the DateTime object.

Usage example (see Also example on shinyapps ):

 library(shiny) library(shinyTime) ui <- fluidPage( titlePanel("shinyTime Example App"), sidebarLayout( sidebarPanel( timeInput("time_input", "Enter time", value = strptime("12:34:56", "%T")) ), mainPanel( textOutput("time_output") ) ) ) server <- function(input, output, session) { output$time_output <- renderText(strftime(input$time_input, "%T")) } shinyApp(ui, server) 

Disclaimer: I am the author of the package. Feedback and suggestions are welcome!

+3
source

Source: https://habr.com/ru/post/1207920/


All Articles