使用DateRangeInput在R Shiny中绘制子集化数据

时间:2017-01-06 19:25:23

标签: r shiny

我正在尝试使用一些输入参数对数据集进行子集化,然后绘制输出。我能够随着时间的推移为不同的团队绘制各种统计数据,但我无法弄清楚如何在输入日期范围内对数据进行子集化。附件是我的服务器和ui。

服务器:

library(shiny)

season = read.csv("2016_Season.csv")
season$date = as.POSIXct(season$date)

function(input, output) {

   adjust <- function() {

     data = season

     #data = data[data$date >= input$dates[1],]
     #data = data[data$date <= input$dates[2],]

     if (input$Team != "All"){                
      data <- data[data$Team == input$Team,] 
     }

     data = data[,c('date',input$Stat)]

      }

   output$distPlot <- renderPlot({

     plot(adjust())
   })
}

UI:

library(shiny)

season = read.csv("2016_Season.csv")
season$date = as.POSIXct(season$date)

shinyUI(fluidPage(

  titlePanel("Time Plot"),

  sidebarPanel(

    fluidRow(
      div(class="span4",
          selectInput('Team',
                      'Team:',
                      c('All',unique(as.character(season$Team)))))
     ),

    fluidRow(
      div(class="span4",                                            
          selectInput("Stat",                                      
                      "Stat:",
                      c('PTS','TRB','AST')))
     ),

    dateRangeInput("dates", 
                   "Date range",
                   start = min(season$date),
                   end = max(season$date))
  ),

  mainPanel(
    plotOutput("distPlot")                     
  )                                           
))

当这两行在服务器中被注释掉时,代码工作正常,但显然日期过滤器不起作用:

 #data = data[data$date >= input$dates[1],]
 #data = data[data$date <= input$dates[2],]

但我删除了评论,我收到错误&#39;需要有限的&#39; xlim&#39;值&#39;而且我不确定如何解决它。

0 个答案:

没有答案