Search code examples
rshinyshinywidgets

Wrong month displayed in airDatepickerInput


I try to use airDatepickerInput in a shiny-app to define a date-range with years-and months only. Everything works fine but in the input box the choosen format is displayed as "2020-00" instead of "2020-01" when i choose January as the starting month for instance.

Here is my code:

    ui <- fluidPage(

    # Application title
    titlePanel("Test"),

    # Sidebar with a slider input for number of bins 
    mainPanel(
          airDatepickerInput("plot_input_daterange",
                             label = "Please choose:",
                             range = TRUE,
                             value = c("2021-10", format(Sys.Date(), "%Y-%m")),
                             clearButton = TRUE,
                             maxDate = format(Sys.Date(), "%Y-%m"),
                             minDate = "2021-10-01",
                             view = "months", 
                             minView = "months", 
                             dateFormat = "yyyy-mm",
                             language= "en",
                             addon = "none")
         

      )
)

# Define server logic required to draw a histogram
server <- function(input, output) {

    
}

# Run the application 
shinyApp(ui = ui, server = server)

How can i fix this issue?


Solution

  • Use a capital "M": dateFormat = "yyyy-MM"

    Please find the related docs here.


    library(shiny)
    library(shinyWidgets)
    
    ui <- fluidPage(
      titlePanel("Test"),
      mainPanel(
        airDatepickerInput("plot_input_daterange",
                           label = "Please choose:",
                           range = TRUE,
                           value = c("2021-10", format(Sys.Date(), "%Y-%m")),
                           clearButton = TRUE,
                           maxDate = format(Sys.Date(), "%Y-%m"),
                           minDate = "2021-10-01",
                           view = "months", 
                           minView = "months", 
                           dateFormat = "yyyy-MM",
                           language= "en",
                           addon = "none")
      )
    )
    
    server <- function(input, output, session) {}
    
    shinyApp(ui = ui, server = server)