konstantinos christodoulou
2023-May-24 07:47 UTC
[R] Filtering DataFrame by Hours using dateRangeInput in Shiny
Dear R Support Team,
I have a dataframe in R with a column named 'start_time,' which is
classified as POSIXct. My objective is to use the dateRangeInput() widget
in Shiny to filter the dataset based on the 'start_time' column,
specifically by selecting hours on a particular day.
My dataframe is given below:
*df* <- data.frame(*start_time* = c(2022-04-01 00:00:00, 2022-04-01
01:00:00, 2022-04-01 04:41:00, 2022-04-01 06:00:00, 2022-04-01
17:01:00, 2022-04-01
18:00:00, 2022-04-01 21:00:00, 2022-04-02 00:00:00, 2022-04-02
01:00:00, 2022-04-02
02:41:00)
However, when I implement this approach,I receive the results grouped by
days (Instead of obtaining the filtered dataframe based on hours, e.g
2022-04-01
04:41:00 until 2022-04-02 01:00:00). I would greatly appreciate your
assistance in resolving this matter.
I also give the Rshinny code:
ui <- fluidPage(
titlePanel("Filtering Data by Hour"), sidebarLayout( sidebarPanel(
dateRangeInput("dateRange", "Select Date Range:", start =
min(df$start_time)
, end = max(df$start_time), min = min(df$start_time), max = max(df$
start_time) ), mainPanel( dataTableOutput("filteredData") ) ) )
server <- function(input, output) { output$filteredData <-
renderDataTable({
filtered_df <- df %>%
filter(start_time >= input$dateRange[1] & start_time <=
input$dateRange[2])
filtered_df }) }
Thank you very much!
[[alternative HTML version deleted]]
Ivan Krylov
2023-May-24 09:46 UTC
[R] Filtering DataFrame by Hours using dateRangeInput in Shiny
? Wed, 24 May 2023 10:47:54 +0300 konstantinos christodoulou <konstantinos.christodoulou1 at gmail.com> ?????:> Dear R Support Team,If you need paid support for Shiny, check out <https://shiny.posit.co/r/help.html>.> I have a dataframe in R with a column named 'start_time,' which is > classified as POSIXct. My objective is to use the dateRangeInput() > widget in Shiny to filter the dataset based on the 'start_time' > column, specifically by selecting hours on a particular day.There's a third-party package called shinyTime which seems to let the user enter times, unlike shiny::dateRangeInput(), which only accepts dates. I'm afraid you'll have to combine information from multiple input widgets yourself by subsetting the resulting POSIXlt objects. Unfortunately, since this e-mail was composed in HTML instead of plain text, we only see a mangled version of it: https://stat.ethz.ch/pipermail/r-help/2023-May/477434.html -- Best regards, Ivan