-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from nick-youngblut/master
- Loading branch information
Showing
18 changed files
with
484 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,17 @@ Package: shinyTime | |
Type: Package | ||
Title: A Time Input Widget for Shiny | ||
Version: 1.0.3.9000 | ||
Authors@R: person("Gerhard", "Burger", email = "[email protected]", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-1062-5576")) | ||
Authors@R: c( | ||
person("Gerhard", "Burger", | ||
email = "[email protected]", | ||
role = c("aut", "cre"), | ||
comment = c(ORCID = "0000-0003-1062-5576")), | ||
person("Nick", "Youngblut", | ||
role = c("aut"), | ||
comment = c(ORCID = "0000-0002-7424-5276")) | ||
) | ||
Description: Provides a time input widget for Shiny. This widget allows intuitive time input in the | ||
'[hh]:[mm]:[ss]' or '[hh]:[mm]' (24H) format by using a separate numeric input for each time | ||
'[hh]:[mm]:[ss]' or '[hh]:[mm]' (24H and 12H) format by using a separate numeric input for each time | ||
component. The interface with R uses date-time objects. See the project page for more | ||
information and examples. | ||
License: GPL-3 | file LICENSE | ||
|
@@ -14,10 +22,11 @@ Imports: | |
URL: https://burgerga.github.io/shinyTime/, | ||
https://github.com/burgerga/shinyTime | ||
BugReports: https://github.com/burgerga/shinyTime/issues | ||
RoxygenNote: 7.2.1 | ||
RoxygenNote: 7.3.1 | ||
Encoding: UTF-8 | ||
Language: en-US | ||
Suggests: | ||
testthat (>= 2.1.0), | ||
spelling, | ||
hms | ||
hms, | ||
bslib |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
library(shiny) | ||
library(bslib) | ||
library(shinyTime) | ||
|
||
start_time <- "23:34:56" | ||
|
||
getTimeInput <- local({ | ||
nTimeInputs <- 0 | ||
timeInputs <- c() | ||
function(label = NULL, value = strptime(start_time, "%T"), ...) { | ||
nTimeInputs <<- nTimeInputs + 1 | ||
if(is.null(label)) label <- paste("genTimeInput", nTimeInputs) | ||
id <- paste0("gen_time_input", nTimeInputs) | ||
timeInputs <<- c(timeInputs, id) | ||
timeInput(id, label, value, ...) | ||
} | ||
}) | ||
|
||
getTimeInputs <- function(widths, ...) { | ||
purrr::map(widths, \(x) getTimeInput(width = paste0(x, "px"), ...)) | ||
} | ||
|
||
widths <- seq(100,500,50) | ||
|
||
cards <- list( | ||
card( | ||
full_screen = TRUE, | ||
card_header("Width"), | ||
layout_column_wrap( | ||
width = 1/3, | ||
card( | ||
card_header("5-minute steps"), | ||
!!!getTimeInputs(widths = widths, minute.steps = 5) | ||
), | ||
card( | ||
card_header("24H"), | ||
!!!getTimeInputs(widths = widths) | ||
), | ||
card( | ||
card_header("12H"), | ||
!!!getTimeInputs(widths = widths, use.civilian = TRUE) | ||
) | ||
) | ||
), | ||
card( | ||
full_screen = TRUE, | ||
card_header("Alignment"), | ||
card( | ||
textInput("text_example", 'Example text input'), | ||
getTimeInput(label = "Enter time"), | ||
getTimeInput(label = "Enter time (5 minute steps)", minute.steps = 5), | ||
getTimeInput(label = "Enter time (civilian)", use.civilian = TRUE) | ||
) | ||
) | ||
) | ||
|
||
sb <- sidebar( | ||
timeInput("source_time", "Desired time", | ||
value = strptime("00:00:00", "%T")), | ||
|
||
actionButton("to_desired_time", "Apply desired time"), | ||
actionButton("to_current_time", "Set to current time") | ||
) | ||
|
||
ui <- page_navbar( | ||
title = "shinyTimeDebug", | ||
sidebar = sb, | ||
nav_spacer(), | ||
nav_panel("Width", cards[[1]]), | ||
nav_panel("Alignment", cards[[2]]) | ||
) | ||
|
||
server <- function(input, output, session) { | ||
updateAllTimeInputs <- function(time, update_source = F) { | ||
timeInputIds <- get("timeInputs", envir = environment(getTimeInput)) | ||
if(update_source) timeInputIds <- c("source_time",timeInputIds) | ||
purrr::map(timeInputIds, \(x) updateTimeInput(session, x, value = time)) | ||
} | ||
|
||
observeEvent(input$to_current_time, updateAllTimeInputs(Sys.time(), update_source = T)) | ||
observeEvent(input$to_desired_time, updateAllTimeInputs(input$source_time)) | ||
|
||
} | ||
|
||
shinyApp(ui, server) |
This file contains 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
Oops, something went wrong.