1

I have been running the following series of commands on sets of .csv files that I am loading into my workspace. Everything was working well, until I tried a new data set.

I keep receiving the error when I try and display the data in my Shiny App: Error in UseMethod("as.xts") : no applicable method for 'as.xts' applied to an object of class "NULL"

I receive no errors when completing the following commands:

Data1 <- read.csv("Data1.csv", stringsAsFactors = FALSE)
Data1$Time <- as.POSIXct(strptime(Data1$Time,"%m/%d/%Y %H:%M:%S" ))
Data1 <- xts(Data1[,-1], order.by=Data1[,1])

It's just weird that it was working for one .csv, and when I copied the same Time column from the first .csv to the new .csv, it doesn't load.

Update Right now, every single input column is being graphed on my dygraph. I know that my issue is in the dygraph(dataSource(), main = "Data"). I know that dataSource() is causing everything to be graphed. How to do I make it so that only the selected input is graphed?

My server.R code is as follows:

dataSource1 <- reactive({
    switch(input$dataSelection1,
        "File1" = File1,
        "File2" = File2,
        "File3" = File3,
        "File4" = File4,
        "File5" = File5) 
})

observeEvent(input$dataSelection1, { 
updateSelectizeInput(session, 'component1', choices = names(dataSource1())) 

}) 

 output$TempRise <- renderDygraph({

    dygraph(dataSource1(), main = "Data") %>%
      dyRangeSelector() %>%
      dyOptions(colors = RColorBrewer::brewer.pal(8, "Dark2"))

})

My ui.R code is as follows: sidebarPanel(

  selectInput('dataSelection', 'DATASELECTION', choice = NULL),


  selectInput("dataSelection1", label = "Choose a File", 
              choices = c("File1","File2", "File3","File4", "File5")),
  selectInput("component1", label = "Choose a Second Component",
              choices = NULL),

 mainPanel(
  dygraphOutput("Data"),   
Gary
  • 2,137
  • 3
  • 23
  • 41
  • You don't call `as.xts` and `xts` doesn't call `as.xts`, so the code you've showed cannot be causing the problem... so you need to provide more context. – Joshua Ulrich Sep 14 '15 at 16:45
  • I don;t call `as.xts` anywhere... which is why I am confused as to why it's showing me this error. When I format the cells in my `.csv` file to be `m/d/yyy h:mm:ss`, could that be causing any issues? – Gary Sep 14 '15 at 16:47
  • 1
    I bet this is an issue related to `excel` style of formatting the `datetime` data type, which I am sure we all faced before – Pork Chop Sep 14 '15 at 16:49
  • How would you guys recommend that I format the `datetime` data type in Excel, before loading it into R? – Gary Sep 14 '15 at 16:51
  • Well, you mention a shiny app and you've tagged your question with "dygraphs". I assume you wrote some code to use both of those packages. The error could be somewhere in there, but you don't show any of that code. – Joshua Ulrich Sep 14 '15 at 16:52
  • Hi Josh, I modified my original post with updated code, and an update on the question at hand. – Gary Sep 15 '15 at 12:05
  • Can anyone look at the update I posted and try to answer the question why dygraphs is plotting all of the inputs, as opposed to the one chosen from `component1`? – Gary Sep 15 '15 at 18:32

0 Answers0