[英]R Shiny App Datetime Range Input rather than only Date
I'm working on building a Shiny App for work and currently have it up and running using a dateRangeInput()
for pulling data.我正在为工作构建一个闪亮的应用程序,目前使用
dateRangeInput()
来启动并运行它来提取数据。 I'm looking for an alternative to this though so that users can be more specific with the range, so they can also choose time as an input as well.不过,我正在寻找一种替代方法,以便用户可以更具体地了解范围,因此他们也可以选择时间作为输入。 So basically my input looks like the following:
所以基本上我的输入如下所示:
dateRangeInput('dates', 'Timeframe To Pull')
and is referenced in my server as并在我的服务器中被引用为
starddate = input$dates[1]
enddate = input$dates[2]
But this is restrictive, as some of their data cannot overlap and will switch profiles in the middle of the day (unscheduled).但这是有限制的,因为他们的一些数据不能重叠,并且会在一天中间切换配置文件(计划外)。 So having an input for datetime range rather than just date range would be huge.
因此,输入日期时间范围而不仅仅是日期范围将是巨大的。 I know that there's a package called
shinyTime
out there, but it only works with times, not datetimes.我知道那里有一个名为
shinyTime
的包,但它只适用于时间,而不适用于日期时间。 So I'm looking to see if there's something cleaner out there.所以我想看看那里是否有更清洁的东西。
Thanks in advance for any help!提前感谢您的帮助!
I've just done a package for you :-)我刚刚为你做了一个包裹:-)
remotes::install_github("stla/DateTimeRangePicker")
The following example is included in the doc.以下示例包含在文档中。
library(DateTimeRangePicker)
library(shiny)
ui <- fluidPage(
br(),
sidebarLayout(
sidebarPanel(
width = 5,
tags$fieldset(
tags$legend("Click to change time"),
dtrpickerInput(
"dtrpicker",
style = paste0(
"background-color: chartreuse; ",
"box-shadow: 0 30px 40px 0 rgba(16, 36, 94, 0.2);"
)
)
)
),
mainPanel(
width = 7,
verbatimTextOutput("dtrpicker")
)
)
)
server <- function(input, output){
output[["dtrpicker"]] <- renderPrint({
input[["dtrpicker"]]
})
}
shinyApp(ui, server)
Note that there's no clock for the second date.请注意,第二个日期没有时钟。 Perhaps it's a bug of the JavaScript library, I don't know.
也许这是 JavaScript 库的错误,我不知道。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.