shinyTime

Published by onesixx on

https://cran.r-project.org/web/packages/shinyTime/index.html
pacman::p_load(shiny, shinyTime)

ui <- fluidPage(
  # Default value is 00:00:00
  timeInput(inputId="time1", "Time:"),
  # Set to current time
  timeInput(inputId="time2", "Time:", value = Sys.time()),
  # Set to custom time
  timeInput(inputId="time3", "Time:", value = strptime("12:34:56", "%T")),
  # Use %H:%M format
  timeInput(inputId="time4", "Time:", seconds = FALSE)
)

server<- function(input, output,session) { }

shinyApp(ui, server)

ex

pacman::p_load(shiny, shinyTime)

ui <- fluidPage( 
  timeInput(inputId="timeVal", "Time:"), 
  actionButton("to_current_time", "Current time")
) 

server <- function(input, output, session) { 
  observeEvent(input$to_current_time, { 
    updateTimeInput(session, "timeVal", value = Sys.time()) 
  }) 
}

shinyApp(ui, server)

ex

pacman::p_load(shiny, shinyTime)

ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      dateInput(inputId="dateRange1",  "Enter initial date: yyyy-mm-dd", value=Sys.Date()),
      timeInput(inputId="time_input1", "Enter time of the initial day",  value=strptime("00:00:00", "%T"))
    ),
    mainPanel(
      textOutput("time_output1")
    )
  )
)

server <- function(input, output, session) {
  vals <- reactiveValues()
  observe({
    selectedDayTime <- str_c(input$dateRange1, strftime(input$time_input1, format="%H:%M:%S"))
    selectedDayTime <- as.POSIXct(selectedDayTime, format="%Y-%m-%d %H:%M:%S",tz="UTC")
    vals$initial_date <- selectedDayTime
    # Check if the Time is a POSIXct object
    test <- inherits(selectedDayTime, "POSIXct")
    print(test)
  })

  output$time_output1 <- renderText({
    value <- as.character(vals$initial_date)
    if(nchar(value) == nchar(as.character(Sys.Date()))){
      value <- paste(value, "00:00:00 ")
    }
    return(value)
  })
}

shinyApp(ui, server)
Categories: R-Shiny

onesixx

Blog Owner

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x