日期输入函数在过滤器中不起作用

时间:2019-10-03 17:31:14

标签: r

下面是我在Flexdashboard中的UI函数。但是,当我尝试使用日期范围时,我并没有离开。下面是示例数据框

df 
Date                              Variable      
21-09-2017  22:05:00               A         
22-09-2017  22:05:00               B
23-09-2017  22:05:00               C
24-09-2017  22:05:00               D
24-09-2017  22:05:00               E

下面的过滤器函数。(不知道我在过滤器函数中在做什么错。我需要过滤器中的变量和日期

output$g1 <- renderPlotly({
    req(input$Plot1)
    if (input$Plot1 == "Trend") {
        plot_data <- df
    }
    if (input$Plot1 == "Trend" & input$b != "All" & input$s2 != NULL) {
        #plot_data <- df %>% filter(variable == input$b)
        plot_data <- df[df$variable %in% input$b & df$Date %in% input$s2,]
    }

下面的UI功能

    selectInput("Plot1","Filter1",choices = c("","Trend","Correlation"))
    output$filter_2 <- renderUI({
    if (input$Plot1 == "") {
    return()
    } else if (input$Plot1 == "Trend") {
      label = "Trend"
      selectInput("b",label,choices = c("All",levels(factor(df$variable))),multiple = TRUE)
    } else {
      label = "First Variable"
      selectInput("b",
                label,
                choices = c(levels(factor(df$variable))))
    }
    })
uiOutput("filter_2")
uiOutput("filter_4")
     output$filter_4 <- renderUI({
       if(input$Plot1 == "Trend"){
         dateRangeInput("s2","Date",min = min(df$Date),max = max(df$Date))
       } else if(input$Plot1 == "Correlation"){
         dateRangeInput("s2","Date",min = min(df$Date),max = max(df$Date))
       }
     })

0 个答案:

没有答案