Требуется проверить, можем ли мы использовать приведенный ниже код для фильтрации как столбцов даты, так и других столбцов.
Приведенный ниже код не работает должным образом в операторе if. Потому что, когда я выбираю ВСЕ и изменяю дату, данных вообще нет, Не знаю, почему
ui.R
library(shiny)
library(shinydashboard)
library(dplyr)
library(DT)
library(lubridate)
source("df.R")
ui <- dashboardPage(
dashboardHeader(disable = TRUE),
dashboardSidebar(disable = TRUE),
dashboardBody(
dateRangeInput("Date", "", start = Sys.Date(), end = Sys.Date(), format = "yyyy-mm-dd", separator = "-"),
selectInput("Tic","",choices = c("ALL",as.character(df$ID)),selected = "ALL"),
actionButton("Submit","Submit"),
dataTableOutput("table")
)
)
server.R
source("utils.R")
library(dplyr)
server <- function(input, output,session) {
df1 <- df %>% filter(Date1 == Sys.Date())
data_1 <- reactiveVal(df1)
observeEvent(input$Submit,{
if (input$Tic == "ALL"){
table_display <- df %>% filter(Date1 %in% input$Date[1] : input$Date[2])
}
else if (input$Tic == "ALL" && input$Date[1] == Sys.Date() && input$Date[2] == Sys.Date())
{
table_display <- df %>% filter(Date1 == Sys.Date())
}
else if (input$Tic != "ALL" && input$Date[1] == Sys.Date() && input$Date[2] == Sys.Date())
{
table_display <- df %>% filter(ID %in% input$Tic & Date1 == Sys.Date())
}
else
{
table_display <- df %>% filter(ID %in% input$Tic & Date1 %in% input$Date[1] : input$Date[2])
}
data_1(table_display)
})
output$table <- DT::renderDataTable({
datatable(data_1())
})
}
df.R
df <- structure(list(Date = structure(c(1541662915.921, 1541562949.500,
1581145671.845, 1581145671.845, 1541662993.957, 1541662915.921,
1541662949.842, 1541662949.845, 1541662949.845, 1581145671.957
), class = c("POSIXct", "POSIXt"), tzone = "UTC"), Date1 = structure(c(17843,
17843, 17844, 17843, 18843, 17843, 18300, 17843, 17843, 18300
), class = "Date"), ID = structure(c(1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 2L, 2L), .Label = c("AAA", "BBB"), class = "factor"),
Value = c(68, 70175, 71107, 702175, 72638, 7238, 739, 738469,
75901, 7106), Status = structure(c(1L, 1L, 2L, 2L, 1L, 2L,
1L, 1L, 2L, 1L), .Label = c("Approved", "Pending"), class = "factor")), row.names = c(NA,
-10L), class = "data.frame")
df$Date <- NULL
df$Status <- NULL
Я имею в виду заполнить столбец с именем "ID" и датой от (Дата начала до даты окончания)