R语言 是否有相对日期的Shiny输入?

gt0wga4j  于 11个月前  发布在  其他
关注(0)|答案(1)|浏览(87)

我想在我的应用程序中添加如下内容:


的数据
是否有现成可用的输入,或者我必须对其进行编程?
最好的祝愿。

2izufjch

2izufjch1#

shiny中没有相对日期输入
你可以使用numericInput来指定你想要返回多少天、多少月或多少年。
例如

numericInput("relativedate","Select days back",value = 30, min = 1)

data <- reactive(data %>% filter(Date >= max(data$Date) - input$relativedate & Date <= max(data$Date)) %>% group_by(col1) %>% summarize(count = n(),mean = mean(col1)

字符串
同样,对于月份和年份,您可以使用lubridate . Read more here

library(lubridate)

numericInput("relativedate","Select months back",value = 2, min = 1)

data <- reactive(data %>% filter(Date >= max(data$Date) %m-% months(input$relativedate) & Date <= max(data$Date)) %>% group_by(col1) %>% summarize(count = n(),mean = mean(col1)

numericInput("relativedate","Select years back",value = 5, min = 1)

data <- reactive(data %>% filter(Date >= max(data$Date) - years(input$relativedate) & Date <= max(data$Date)) %>% group_by(col1) %>% summarize(count = n(),mean = mean(col1)

相关问题