Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using updateTimeInput to clear the form #26

Open
majazaloznik opened this issue Sep 25, 2024 · 0 comments
Open

using updateTimeInput to clear the form #26

majazaloznik opened this issue Sep 25, 2024 · 0 comments

Comments

@majazaloznik
Copy link

Given that you can pass value = "" to timeInput() and start with an empty form, i expected that i could pass the same argument to updateTimeInput, but that throws an error. Also passing value = NULL doesn'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 as value, but that seems rather kludgy..


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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant