library(shiny)
library(shinyTime)
ui <- fluidPage(
titlePanel("shinyTime Example App"),
sidebarLayout(
sidebarPanel(
timeInput("time_input1", "Enter time", value = ""),
timeInput("time_input2", "Enter time (5 minute steps)", value = "", minute.steps = 5),
actionButton("to_current_time", "Current time"),
actionButton("clear_time", "Clear")
),
mainPanel(
textOutput("time_output1"),
textOutput("time_output2")
)
)
)
server <- function(input, output, session) {
output$time_output1 <- renderText(strftime(input$time_input1, "%T"))
output$time_output2 <- renderText(strftime(input$time_input2, "%R"))
observeEvent(input$to_current_time, {
updateTimeInput(session, "time_input1", value = Sys.time())
updateTimeInput(session, "time_input2", value = Sys.time())
})
observeEvent(input$clear_time, {
updateTextInput(session, "time_input1", value = "")
updateTextInput(session, "time_input2", value = "")
})
}
shinyApp(ui, server)
Given that you can pass
value = ""totimeInput()and start with an empty form, i expected that i could pass the same argument toupdateTimeInput, but that throws an error. Also passingvalue = NULLdoesn't work and just keeps the existing values. Is there any way to clear the fields?Curiously, what does work is to instead use
updateTextInput(), and passing an empty string asvalue, but that seems rather kludgy..