HI everybody, I've added a date filter to my Shiny App. Now I want to filter the data frame dynamically according to the date input.
I tried this as follows in die ui.R:
fluidPage(
selectInput(
"analysis_period",
"analysie period:",
c(
"Last Year" = "LY",
"Past 90 days" = "ND",
"Past 30 days" = "TD",
"Last Week" = "LW"
)
)
)
In my server section I have:
>date_input <- reactive({
if (input$analysis_period== "NT") {
as.Date(Sys.time()) - 90
}
else if (input$analysis_periodm == "DT") {
as.Date(Sys.time()) - 30
}
else if (input$analysis_periodum == "LW") {
as.Date(Sys.time()) - 7
}
else if (input$analysis_period == "LY") {
m = as.POSIXlt(as.Date(Sys.time()))
m$year = m$year - 1
m
}
Then I want to load the data frame and filter it using the filter:
data2 = data[, c('A', 'B', 'C')]
data2 <- filter(data2, date_input())
But when I start the app I always get the error:
Error in filter_impl(.data, quo) :
Evaluation error: Operation not allowed without an active reactive context.
(You tried to do something that can only be done from inside a reactive
expression or observer.).
What am I doing wrong here? Thanks!!