2014-07-01 49 views
3

我使用Shiny在R中開發應用程序,我想爲我正在使用的dateInput使用minViewMode的datepicker選項。Shiny dateInput不包括minViewMode選項

我已經在Shiny官方文檔中檢查過,似乎這個選項還沒有被考慮用於dateInput小部件。我怎麼能在我的R代碼中使用這個選項?這是我的ui.R代碼:

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

感謝

+1

這是在這裏找到答案//計算器。 COM /問題/ 31152960 /只顯示月功能於daterangeinput - 或 - dateinput換一個閃亮-APP-R-編程與規範 – shosaco

回答

0

嘗試定義這個自定義輸入,並與您提出的呼叫時使用:HTTP:

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")