gpt4 book ai didi

r - Shiny 的 dateInput 不包括 minViewMode 选项

转载 作者:行者123 更新时间:2023-12-01 14:30:39 26 4
gpt4 key购买 nike

我正在使用 Shiny 在 R 中开发一个应用程序,我想将 minViewMode 的 datepicker 选项用于我正在使用的 dateInput。

我查看了 Shiny 官方文档,似乎没有为 dateInput 小部件考虑这个选项。我如何在我的 R 代码中使用这个选项?这是我的 ui.R 代码:

dateInput("InitialDateGlobalViewTrafficSplit"
,h4("Initial date")
,value=as.Date(InitialDate)
,min = ("2012-01-01")
,weekstart = 1
# ,minViewMode = 1 # Ideal solution :)
)

谢谢

最佳答案

尝试定义此自定义输入并将其用于您建议的调用:

 mydateInput <- function(inputId, label, value = NULL, min = NULL, max = NULL,
format = "yyyy-mm-dd", startview = "month", weekstart = 0, language = "en", minviewmode="months",
width = NULL) {

# If value is a date object, convert it to a string with yyyy-mm-dd format
# Same for min and max
if (inherits(value, "Date")) value <- format(value, "%Y-%m-%d")
if (inherits(min, "Date")) min <- format(min, "%Y-%m-%d")
if (inherits(max, "Date")) max <- format(max, "%Y-%m-%d")

htmltools::attachDependencies(
tags$div(id = inputId,
class = "shiny-date-input form-group shiny-input-container",
style = if (!is.null(width)) paste0("width: ", validateCssUnit(width), ";"),

controlLabel(inputId, label),
tags$input(type = "text",
# datepicker class necessary for dropdown to display correctly
class = "form-control datepicker",
`data-date-language` = language,
`data-date-weekstart` = weekstart,
`data-date-format` = format,
`data-date-start-view` = startview,
`data-date-min-view-mode` = minviewmode,
`data-min-date` = min,
`data-max-date` = max,
`data-initial-date` = value
)
),
datePickerDependency
)
}

`%AND%` <- function(x, y) {
if (!is.null(x) && !is.na(x))
if (!is.null(y) && !is.na(y))
return(y)
return(NULL)
}

controlLabel <- function(controlName, label) {
label %AND% tags$label(class = "control-label", `for` = controlName, label)
}

datePickerDependency <- htmlDependency(
"bootstrap-datepicker", "1.0.2", c(href = "shared/datepicker"),
script = "js/bootstrap-datepicker.min.js",
stylesheet = "css/datepicker.css")

关于r - Shiny 的 dateInput 不包括 minViewMode 选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24512077/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com