[我正在尝试引用应用用户的多个日期范围输入。但是,日期范围输入的数量可能每次都不同。例如,这次我有3个时段,下次我有17个时段可以抓住。我应该如何编写endDate以让R自动获取最后一个日期范围输入?]
ui <-fluidPage(
dateRangeInput('dateRange1', label = 'period1', start = '', end = '' ),
dateRangeInput('dateRange2', label = 'period2', start = '', end = '' ),
dateRangeInput('dateRange3', label = 'period3', start = '', end = '' ),
dateRangeInput('dateRange4', label = 'period4', start = '', end = '' ),
dateRangeInput('dateRange5', label = 'period5', start = '', end = '' ),
dateRangeInput('dateRange6', label = 'period6', start = '', end = '' ),
dateRangeInput('dateRange7', label = 'period7', start = '', end = '' ),
dateRangeInput('dateRange8', label = 'period8', start = '', end = '' ),
dateRangeInput('dateRange9', label = 'period9', start = '', end = '' ),
dateRangeInput('dateRange10', label = 'period10', start = '', end = '' ),
dateRangeInput('dateRange11', label = 'period11', start = '', end = '' ),
dateRangeInput('dateRange12', label = 'period12', start = '', end = '' ),
dateRangeInput('dateRange13', label = 'period13', start = '', end = '' ),
dateRangeInput('dateRange14', label = 'period14', start = '', end = '' ),
dateRangeInput('dateRange15', label = 'period15', start = '', end = '' ),
dateRangeInput('dateRange16', label = 'period16', start = '', end = '' ),
dateRangeInput('dateRange17', label = 'period17', start = '', end = '' ),
dateRangeInput('dateRange18', label = 'period18', start = '', end = '' ),
dateRangeInput('dateRange19', label = 'period19', start = '', end = '' ),
dateRangeInput('dateRange20', label = 'period20', start = '', end = '' ),
actionButton("submit", "Submit")
)
server <- function(input, output, session) {
observeEvent(input$submit, {
startDate = input$dateRange1[1]
endDate = ???
})
}
答案 0 :(得分:1)
为了节省打字能量,我们可以在有意义时使用包装函数。
solves POST /solves(.:format) solves#create
new_solf GET /solves/new(.:format) solves#new
edit_solf GET /solves/:id/edit(.:format) solves#edit
solf GET /solves/:id(.:format) solves#show
PATCH /solves/:id(.:format) solves#update
PUT /solves/:id(.:format) solves#update
DELETE /solves/:id(.:format) solves#destroy
答案 1 :(得分:0)
您可以使用
获取所有dateRangeXX
输入的列表
dateRanges <- grep('dateRange', names(input), value = T)
然后,您可以通过将dateRange输入转换为日期矩阵并计算开始日期和结束日期来提取最小值和最大值。
dateMatrix <- sapply(dateRanges, function(x) {input[[x]]})
dateMin <- min(dateMatrix[ ,1], na.rm = T)
dateMax <- max(dateMatrix[ ,2], na.rm = T)