R闪亮日期范围仅输入月份年份 [英] R Shiny DateRange Input month year only
问题描述
是否可以在Shiny中破解或创建 dateRangeInput()
选择器,以便仅选择月-年(无日)或自动选择第一个所选月份的哪一天没有显示日期选择?还是我应该创建另一个月份日期选择器(滑块,选择框...)
dateRangeInput('dateRange',label = Pédioded'analyse:,format = mm / yyyy,language = fr,
start = Sys.Date()%m-%months(12),end = Sys.Date(),startview = year,分隔符=-)
我要选择的是删除此步骤日期:
示例2,仅显示月份和年份
#rm(list = ls())
库(发光)
monthStart<-function(x){
x<-as .POSIXlt(x)
x $ mday<-1
as.Date(x)
}
ui<-basicPage(dateRangeInput('dateRange', label =Pédioded'analyse:,format = mm / yyyy,language = fr,start = Sys.Date(),end = Sys.Date(),startview = year,分隔符=- ),
textOutput( SliderText)
)
服务器<-ShinyServer(function(input,output,session){
Date<-reactValues ()
观察({
Dates $ SelectedDates<-c(as.character(format(input $ dateRange [1],format =%m /%Y)),as.character( format(input $ dateRange [2],format =%m /%Y)))
})
output $ SliderText<-renderText({Dates $ SelectedDates})
} )
ShinyApp(ui = ui,服务器=服务器)
Is there a way to Hack or Create a dateRangeInput()
selector in Shiny so that it selects only month-year (no day) or that it automatically selects the first day of the selected month without displaying a day choice ? Or should I create another month-date picker (sliders, selectbox...)
dateRangeInput('dateRange',label = "Pédiode d'analyse : ",format = "mm/yyyy",language="fr",
start = Sys.Date() %m-% months(12), end=Sys.Date(),startview = "year",separator = " - ")
What i want is to delete this step when choosing the date : dateRangeInput
Have a look at this custom function monthStart
below which can be used to force the date to the first date of that month and year
Example 1, Display the first day of a given month. This may be useful if you want to use the date object for later use in your app, so it will always point to the first day of a given month and year
#rm(list=ls())
library(shiny)
monthStart <- function(x) {
x <- as.POSIXlt(x)
x$mday <- 1
as.Date(x)
}
ui <- basicPage(dateRangeInput('dateRange',label = "Pédiode d'analyse : ",format = "mm/yyyy",language="fr",start = Sys.Date(), end=Sys.Date(),startview = "year",separator = " - "),
textOutput("SliderText")
)
server <- shinyServer(function(input, output, session){
Dates <- reactiveValues()
observe({
Dates$SelectedDates <- c(as.character(monthStart(input$dateRange[1])),as.character(monthStart(input$dateRange[2])))
})
output$SliderText <- renderText({Dates$SelectedDates})
})
shinyApp(ui = ui, server = server)
Example 2, Display only the month and year
#rm(list=ls())
library(shiny)
monthStart <- function(x) {
x <- as.POSIXlt(x)
x$mday <- 1
as.Date(x)
}
ui <- basicPage(dateRangeInput('dateRange',label = "Pédiode d'analyse : ",format = "mm/yyyy",language="fr",start = Sys.Date(), end=Sys.Date(),startview = "year",separator = " - "),
textOutput("SliderText")
)
server <- shinyServer(function(input, output, session){
Dates <- reactiveValues()
observe({
Dates$SelectedDates <- c(as.character(format(input$dateRange[1],format = "%m/%Y")),as.character(format(input$dateRange[2],format = "%m/%Y")))
})
output$SliderText <- renderText({Dates$SelectedDates})
})
shinyApp(ui = ui, server = server)
这篇关于R闪亮日期范围仅输入月份年份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!