-1

I have data to be plotted as series which is uploded by user. However, the data is for one year and I would like to display 2 months for instance, january and february when the user needs to analyze the pattern of these months. That's why i thought that dateRangeInput can be useful but i dont know how can i bind with plot?

for data: http://www.filedropper.com/quo

EDITED: I used the reactive argument in order get the inputs. However, it shows another error: Error in charToDate(x) : character string is not in a standard unambiguous format.

enter image description here

 library(shiny)
  shinyUI(fluidPage( 
    titlePanel("Time Series Study"), 
     sidebarLayout(
      sidebarPanel(
       fileInput('file2', 'Choose Quotation File:', accept=c('text/csv', 'text/comma-separated-values,text/plain', '.csv'), multiple = FALSE),
       dateRangeInput("range",
                 "Date Range:",
                 start = "start",
                 end   = "end",
                 min = "2012.01.01",
                 max   = "2012.01.31")
        ),

        mainPanel(
        plotOutput("distPlot")  )  ) ))


 #server.r


  library(shiny)
  library(ggplot2)
     shinyServer(function(input, output) {


     dataInput <- reactive({

     `uploadedsamplefile` <- read.csv(input$file2$datapath, sep=";",check.names = FALSE)
      uploadedsamplefile1 <- uploadedsamplefile
      xx<-cbind(`uploadedsamplefile1`[1:4])
      xx$`Datee` <- as.Date( xx$`Datee`, '%d.%m.%Y')
      xx$`Datee` <- subset( xx$`Datee`,   as.Date("input$start") <= xx$`Datee`  &&  xx$`Datee` <= as.Date("input$end"))
    })
     output$distPlot <- renderPlot({
       y <- ggplot(xx, aes(x=`Datee`)) +  geom_line(aes(y=(`A`), colour = "A")) + geom_line(size=1,aes(y=(`B`), colour = "B")) + 
  geom_line(size=1,aes(y=(`C`), colour = "C")) 
       y }) })
can.u
  • 515
  • 1
  • 4
  • 12

1 Answers1

1

To access the start and end dates in your example use input$range[1] for the start date and input$range[2] to access the end date.

hvollmeier
  • 2,956
  • 1
  • 12
  • 17
  • I have an error about Error in charToDate(x) : character string is not in a standard unambiguous format. – can.u Jan 22 '16 at 17:48
  • You most likely get this error because the dates in your example are not in the standard date format. Try: `min="2012-01-01"' and 'max= "2012-01-01"`. Further the start and end parameters expect a properly formatted date as well. In the example above you assign character strings `"start"` and '"end"' ! – hvollmeier Jan 22 '16 at 18:05
  • It does not work because I define my data vector with xx$`Datee` <- as.Date( xx$`Datee`, '%d.%m.%Y'). Eventhough I changed, i have again same error. character string is not in a standard unambiguous format – can.u Jan 22 '16 at 18:45
  • I am not talking about the vector. The parameters for start/ end in the ui-part are not valid dates. For instance: start ="start" feeds a character string to the parameter `start` where a date is expected ! You either have to assign a valid date like `"2012-01-31"` ( or in another format like (`as.Date("2012.01.31", "%Y.%m.%d )` or a valid date variable. – hvollmeier Jan 22 '16 at 19:10