Comments (2)
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.
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)
- Shiny input change is getting triggered for daterangepicker before clicking on apply button. HOT 7
- Allow specification of range names without using R names HOT 3
- Release daterangepicker 0.2.0
- Display chosen range in a custom format HOT 1
- Button Input Option HOT 2
- Interaction with Shiny bookmarking is broken? HOT 7
- Time does not match selection HOT 4
- Add Day / Week / Month / Quarter / Year calendar modes HOT 8
- update `ranges` with ? `updateDaterangepicker` HOT 7
- Release daterangepicker 0.2.0
- How to set time zones? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from daterangepicker.