使用Shiny中的dateRangeInput链接数据

时间:2017-11-15 13:55:22

标签: r ggplot2 shiny visualization

    ## app.R ##
    library(shiny)
    library(shinydashboard)
    library(ggplot2)
    library(data.table)

    ui <- dashboardPage(
      dashboardHeader(title = "Smart Survey Insights"),
      dashboardSidebar(
        dateRangeInput("dateRange", "Please choose date", "2017-01-01", NULL),
        checkboxInput("comparePreviousPeriod", "Compare to previous period")
      ),
      dashboardBody(
        fluidRow(
          column(12, plotOutput("boxPlot")),
        )
      )
    )

    server <- function(input, output) { 


    mydata <- data_frame(ended = c("14/11/2016 13:37", "14/11/2016 13:37",
"14/11/2016 13:47", "14/11/2016 13:51", "14/11/2016 13:51"),
task = c("Find licensing information", "Sign in to my existing account",
"Sign in to my existing account", "Bus registrations", "Make changes to my existing Operator’s Licence"), taskLevelOfDifficulty = c("Extremely difficult", "Extremely easy", "Neither easy nor difficult", "Extremely difficult", "Extremely easy"))

   mydata <- mydata  %>% mutate(ended = as.Date(ended, format = "%Y-%m-%d"))




      filteredData <- mydata %>% filter(ended >= input$date_range[1] && mydata$ended <= input$date_range[2])
      output$boxPlot <- renderPlot(ggplot(filteredData, aes(taskLevelOfDifficulty))) + geom_bar()

      }

    shinyApp(ui, server)

我的代码似乎不起作用,问题是我的“已结束”列具有14/11/2016 13:37格式,而dateRangeInput具有yyyt-mm-dd格式。我不知道如何将我的图表与dateRangeInput

相关联

1 个答案:

答案 0 :(得分:2)

我必须修复相当多的代码,所以请查看并确保您了解过滤和输出的依赖性。例如,我将SELECT REPORTS.month_id ,REPORTS.store_id ,SUM(REPORTS.day_amount) AS GRAND_TOTAL FROM REPORTS GROUP BY REPORTS.month_id, REPORTS.store_id 移到dataframe

之外
server

enter image description here