Reputation: 57176
How can I have year input only?
I have this date input below which gives me dates from 2014-10-01,
dateInput(
inputId = "date_from",
label = "Select time period:",
value = "2014-10-01",
format = "dd-mm-yyyy"
)
But I don't need the months and dates, only years that I need,
dateInput(
inputId = "year_from",
label = "Select time period:",
value = "2014",
format = "yyyy"
)
It does not work obviously as I still see the months and dates being displayed.
Any ideas?
Upvotes: 2
Views: 3906
Reputation: 330
With reference to Dean Attali answer, we can update the code as below to show the years till our current year only.
selectInput(
inputId = "date_from",
label = "Select time period:",
choices = 2014:as.numeric(format(Sys.Date(),"%Y"))
)
Upvotes: 3
Reputation: 26313
If you don't need months and days, then I'd argue that what you want is not dates but just year. If you just want year, then I would use a selectInput
instead of a dateInput
. Usually dateInput
are used when you literally want a full date, but it makes a lot more sense to just show a select box with years if that's all you need. It's also a lot easier for the user to use from a user-experience point of view.
selectInput(
inputId = "date_from",
label = "Select time period:",
choices = 2014:2100
)
Upvotes: 8