0

Is there a way to imitate the daysofweekdisabled found in dateInput?

I want people to select only mondays.

Charbel
  • 63
  • 4
  • Welcome to stack overflow. It's easier to help you if you make your question reproducible by including data to enable testing and verification of possible solutions. [Link for guidance on asking questions](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – Peter May 11 '22 at 07:35

1 Answers1

1

Unfortunately, there is no built-in feature of function dateRangeInput. However, one can create a hook to evaluate if a given input is valid or not i.e. both start and end date is on a Monday:

library(shiny)
library(lubridate)

ui <- fluidPage(
  dateRangeInput("daterange1", "Date range:",
    start = "2001-01-01",
    end   = "2010-12-31"
  ),
  textOutput("daterange1_valid")
)

server <- function(input, output, session) {
  output$daterange1_valid <- renderText({
    is_valid <- all(input$daterange1 %>% map_lgl(~ wday(.x, label = TRUE) == "Mon"))

    ifelse(is_valid, "valid", "not valid. Start and end must be on a Monday!")
  })
}

shinyApp(ui, server)

enter image description here

Another way is to just use two dateInput elements instead. This will allow you to also color days other than Monday grey in the picker.

danlooo
  • 10,067
  • 2
  • 8
  • 22