1

I've been banging my head against the wall trying to figure out what this issue for the last hour, so I figured I'd pick your collective brains on this one. Basically, I have a shiny app that behaves as expected when run from within RStudio. When I uploaded it to shinyapps.io, however, the X-axis seems to be offset so that it goes from 18:00:00 to 18:00:00 rather than from 00:00:00 to 00:00:00 as it does in the local app. I'm simply using R's plot() function, so I don't believe that it's a library issue. I've also re-uploaded my project to make sure that it isn't a version issue either. The code to create the graph is as follows:

load("primary.rdata")


#Gets all the data sets for each of from a week's time
useIndices <- getSelectedIndices(fromTime = "2015-01-20", toTime = "2015-01-21", interval = 5)
GSub <- Primary[useIndices, ]

useIndices2 <- getSelectedIndices(fromTime = "2015-01-21", toTime = "2015-01-22", interval = 5)
GSub2 <- Primary[useIndices2, ]

useIndices3 <- getSelectedIndices(fromTime = "2015-01-22", toTime = "2015-01-23", interval = 5)
GSub3 <- Primary[useIndices3, ]

useIndices4 <- getSelectedIndices(fromTime = "2015-01-23", toTime = "2015-01-24", interval = 5)
GSub4 <- Primary[useIndices4, ]

useIndices5 <- getSelectedIndices(fromTime = "2015-01-24", toTime = "2015-01-25", interval = 5)
GSub5 <- Primary[useIndices5, ]

useIndices6 <- getSelectedIndices(fromTime = "2015-01-25", toTime = "2015-01-26", interval = 5)
GSub6 <- Primary[useIndices6, ]

useIndices7 <- getSelectedIndices(fromTime = "2015-01-26", toTime = "2015-01-27", interval = 5)
GSub7 <- Primary[useIndices7, ]



#Sets color palettes for different days of the week
reds <- colorRampPalette(c("firebrick1", "firebrick4")) (4)
oranges <- colorRampPalette(c("darkorange", "darkorange4")) (4)
yellows <- colorRampPalette(c("goldenrod1", "goldenrod4")) (4)
greens <- colorRampPalette(c("green", "lightgreen")) (4)
blues <- colorRampPalette(c("blue", "lightblue")) (4)
purples <- colorRampPalette(c("darkmagenta", "darkorchid")) (4)
pinks <- colorRampPalette(c("deeppink", "deeppink4")) (4)
         
plot(0, 0, type="l",main="All Our Network Traffic Over One Week", sub="Starting January 20th until January 27th", ylim=c(0, 37), xlab="Time", ylab="Networ Traffic (MB/sec)", axes=FALSE)
         

par(new=TRUE)

plot(GSub7$unixTime, GSub7$avgDown, type="l", ylim=c(0, 37), xlab="", ylab="", axes=FALSE, col = pinks[1])

par(new=TRUE)
plot(GSub7$unixTime, GSub7$avgUp, type="l", ylim=c(0, 37), xlab="", ylab="", axes=FALSE, col = pinks[1])
      
par(new=TRUE)
plot(GSub7$unixTime, GSub7$maxDown, type="l", ylim=c(0, 37), xlab="", ylab="", axes=FALSE, col = pinks[1], lty=3)

par(new=TRUE)     
plot(GSub7$unixTime, GSub7$maxUp, type="l", ylim=c(0, 37), xlab="", ylab="", axes=FALSE, col = pinks[1], lty=3)

axis(1, at=GSub7$unixTime[ GSub7$unixTime%%3600 == 0], labels=GSub7$Time[ which(grepl(":00:00", GSub7$Time)) ])
axis(2, labels=TRUE)
      
grid(nx=24, ny=7)
         
# Include loess curve
oneWeek <- getSelectedIndices(fromTime = "2015-01-20", toTime = "2015-01-27", interval = 5)
Psub <- Primary[oneWeek,]
times <- seq(0, 24, by=0.25)
#load("loess.rdata")
Loess <- loess(Psub$avgDown ~ Psub$deciTime, span=.25)
Loess.Pr <- predict(Loess, times)
par(new = TRUE)
plot(Loess.Pr ~ times, type="l", ylim=c(0, 37), xlab="", ylab="", axes=FALSE, col="black", lty=4, lwd=2)

The uploaded shiny app is here. If you open it up, you'll notice that the loess curve doesn't follow the graph that's there, but rather the original graph with the correct axes. Anyway, all help is greatly appreciated.

-Paul

paul jerman
  • 601
  • 5
  • 13
  • It's much easier to help if you make your [reproducible example as minimal](http://stackoverflow.com/help/mcve) as possible – MrFlick Feb 03 '15 at 06:08
  • Thanks for the advice. I've cut it down to the essentials, but to run it, they would need my primary.rdata file, and i'm not sure if it's possible to upload files on these forums. – paul jerman Feb 03 '15 at 06:40
  • It's not possible to upload files here. See [how to create a reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) for suggestions on including sample data. Also, the code snipped feature is for HTML/Javascript only. Do not but code in a snippet block. – MrFlick Feb 03 '15 at 06:42

1 Answers1

0

I'm going to take a shot in the dark here and guess that it is has something to do with the difference in the way your local machine handles time relative to how the shinyapps.io server handles time. Try storing your time data in a different format, such as character values. Then include code in server.R that converts that information into POSIXlt values, such as strptime(time, format = "%F %T").

Paul de Barros
  • 1,170
  • 8
  • 22