Last active
April 1, 2022 12:58
-
-
Save moodymudskipper/4ae109b16f400925eab08fd1a5c2b4c2 to your computer and use it in GitHub Desktop.
date_picker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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