Created
May 15, 2020 05:27
-
-
Save micstr/49641c2767765bf0d0be716f6634a89e to your computer and use it in GitHub Desktop.
Shiny inptDateRange setting min view to only show months for example not days
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
# Thanks to David https://stackoverflow.com/a/54922170/4606130 | |
# date range input set to month with minview | |
# https://stackoverflow.com/a/54922170/4606130 | |
dateInput2 <- function(inputId, label, minview = "days", maxview = "decades", ...) { | |
d <- shiny::dateInput(inputId, label, ...) | |
d$children[[2L]]$attribs[["data-date-min-view-mode"]] <- minview | |
d$children[[2L]]$attribs[["data-date-max-view-mode"]] <- maxview | |
d | |
} | |
dateRangeInput2 <- function(inputId, label, minview = "days", maxview = "decades", ...) { | |
d <- shiny::dateRangeInput(inputId, label, ...) | |
d$children[[2L]]$children[[1]]$attribs[["data-date-min-view-mode"]] <- minview | |
d$children[[2L]]$children[[3]]$attribs[["data-date-min-view-mode"]] <- minview | |
d$children[[2L]]$children[[1]]$attribs[["data-date-max-view-mode"]] <- maxview | |
d$children[[2L]]$children[[3]]$attribs[["data-date-max-view-mode"]] <- maxview | |
d | |
} | |
library(shiny) | |
shinyApp( | |
ui = fluidPage( | |
dateInput2("test1", "Year", startview = "year", minview = "months", maxview = "decades"), | |
dateRangeInput2("test2", "Years", startview = "year", minview = "months", maxview = "decades", | |
format = "yyyy-mm") | |
), | |
server = function(input, output, session) {} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment