Skip to content

Instantly share code, notes, and snippets.

@moodymudskipper
Last active April 1, 2022 12:58
Show Gist options
  • Save moodymudskipper/4ae109b16f400925eab08fd1a5c2b4c2 to your computer and use it in GitHub Desktop.
Save moodymudskipper/4ae109b16f400925eab08fd1a5c2b4c2 to your computer and use it in GitHub Desktop.
date_picker
date_picker <- function(time = FALSE) {
withr::with_package("shiny",{
ui <- fluidPage(
shinyWidgets::airDatepickerInput(
inputId = "widget",
timepicker = time,
inline = TRUE
),
if(time) actionButton("button", "ok")
)
server <- function(input, output, session) {
my_date <- renderText(input$widget)
if(time) {
observeEvent(input$button, {
stopApp(as.POSIXct(as.numeric(my_date()), origin = "1970-01-01 00::00:00"))
})
} else {
observeEvent(input$widget, {
stopApp(as.Date(as.numeric(my_date()), origin = "1970-01-01"))
})
}
}
runGadget(ui, server)
})
}
x <- date_picker(TRUE)
print(x)
y <- date_picker()
print(y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment