Git Product home page Git Product logo

Comments (2)

ltuijnder avatar ltuijnder commented on June 13, 2024

You have to make sure that the selected start and end date also corresponds to the ranges that you want to have by default selected. If your specified start and end date does not correspond to : Today/Yesterday/Last Month it will be default select the Custom Range:

library(shiny)
library(daterangepicker)

## UI ##########################
ui <- fluidPage(
  daterangepicker(
    inputId = "daterange",
    label = "Pick a Date",
    #start = Sys.Date() , end = Sys.Date(),            # -> Today will be selected
    start = Sys.Date() - 1, end = Sys.Date(),          # -> Yesterday will be selected
    #start = Sys.Date() - months(1), end = Sys.Date(), # -> Last Month will be selected
    #start = Sys.Date() - 15, end = Sys.Date(),        # -> Custrom range will be selected
    ranges = list("Today" = Sys.Date(),
      "Yesterday" = c(Sys.Date() - 1, Sys.Date()),
      "Last Month" = c(Sys.Date() - months(1), Sys.Date())
    ),
    icon = icon("calendar")
  ),
  verbatimTextOutput("print"),
)

## SERVER ##########################
server <- function(input, output, session) {
  output$print <- renderPrint({
      req(input$daterange)
      input$daterange
    })
}

shinyApp(ui, server)

from daterangepicker.

trafficonese avatar trafficonese commented on June 13, 2024

Somehow this Sys.Date() - months(1) isn't working anymore.
The correct version now is Sys.Date() %m-% base::months(1)

So the correct example would look like this:

library(shiny)
library(daterangepicker)
library(lubridate)

## UI ##########################
ui <- fluidPage(
  daterangepicker(
    inputId = "daterange",
    label = "Pick a Date",
    #start = Sys.Date() , end = Sys.Date(),            # -> Today will be selected
    start = Sys.Date() - 1, end = Sys.Date(),          # -> Yesterday will be selected
    #start = Sys.Date() - months(1), end = Sys.Date(), # -> Last Month will be selected
    #start = Sys.Date() - 15, end = Sys.Date(),        # -> Custrom range will be selected
    ranges = list("Today" = Sys.Date(),
                  "Yesterday" = c(Sys.Date() - 1, Sys.Date() - 1),
                  "Last Month" = c(floor_date(Sys.Date() %m-% base::months(1), "month"),
                                   floor_date(Sys.Date(), "month") - 1)
    ),
    icon = icon("calendar")
  ),
  verbatimTextOutput("print")
)

## SERVER ##########################
server <- function(input, output, session) {
  output$print <- renderPrint({
    req(input$daterange)
    print(input$daterange)
  })
}

shinyApp(ui, server)

from daterangepicker.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.