我正在尝试创建一个应用,其中用户选择适当的日期,之后将其用作显示和汇总所选数据集的过滤器。
library(shiny)
library(shinydashboard)
start_date <- "2019-06-30"
end_date <- "2021-06-30"
VP_all <- data.frame(code= c("VP001", "VP002", "VP003", "VP004", "VP005", "VP006", "VP007", "VP008"),
available = c("Yes", "Yes", "No", "No", "Yes", "Yes", "No", "No"),
date = c("2019-09-28", "2021-09-28", "2024-07-12", "2022-11-03", "2021-11-26", "2019-09-28", "2021-09-28", "2024-07-12"))
#Recovery option 5 specific function
select <- function(df, x){
VP_EB <- subset(df, df$available == "Yes" & df$date > x)
return(VP_EB)
}
#################################
#UI
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
tabsetPanel(
tabPanel("Settings",
br(),
column(width = 8,
box(title = "Set parameters", id = "RO_05_param_box", width = NULL, solidHeader = TRUE, status ="primary", collapsible = TRUE,
box(dateRangeInput("date_range_view", h6("Determine the sell period"), start = start_date, end = end_date, min = start_date, max = end_date),
dateRangeInput("date_range_view2", h6("Determine the repurchase period"), start = start_date, end = end_date, min = start_date, max = end_date))
)
),
column(width = 12,
box(title = "Review available financial assets", id = "RO_05_rewiew_box", width = NULL, solidHeader = TRUE, status = "primary", collapsed = FALSE, collapsible = TRUE,
dataTableOutput("RO_05_available"))
)
)
)
)
)
server <- function(input, output) {
observe({
output$RO_05_available <- renderDataTable({
df_RO05 <- select(VP_all, date_range_view2[2])
},options = list(scrollX = TRUE, scrollY = "400px"))
})
}
# Run the application
shinyApp(ui = ui, server = server)
我不断出错
评估错误:找不到对象“ date_range_view2”
我尝试使用select(VP_all, req(date_range_view2[2]))
,但这也不起作用-但是我认为这是没有必要的,因为在ui中设置了date_range_view2的值。
我在做什么错了?