【问题标题】:Shiny graph has offset axis on shinyapps.ioShiny 图形在 shinyapps.io 上有偏移轴
【发布时间】:2015-02-03 05:40:42
【问题描述】:

在过去的一个小时里,我一直在拼命想弄清楚这个问题是什么,所以我想我会在这个问题上集思广益。基本上,我有一个闪亮的应用程序,当从 RStudio 中运行时,它的行为符合预期。但是,当我将它上传到 shinyapps.io 时,X 轴似乎是偏移的,因此它从 18:00:00 到 18:00:00 而不是从 00:00:00 到 00:00:00它在本地应用程序中。我只是使用 R 的 plot() 函数,所以我不认为这是库问题。我还重新上传了我的项目,以确保它也不是版本问题。创建图的代码如下:

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)

上传的闪亮应用是here。如果你打开它,你会注意到黄土曲线没有跟随那里的图表,而是带有正确轴的原始图表。无论如何,非常感谢所有帮助。

-保罗

【问题讨论】:

  • 如果您将reproducible example as minimal 设为尽可能,帮助会容易得多
  • 感谢您的建议。我已将其缩减为基本内容,但要运行它,他们需要我的 primary.rdata 文件,而且我不确定是否可以在这些论坛上上传文件。
  • 这里不能上传文件。有关包含示例数据的建议,请参阅how to create a reproducible example。此外,代码截断功能仅适用于 HTML/Javascript。不要只在 sn-p 块中编码。

标签: r shiny


【解决方案1】:

我将在这里暗中进行拍摄,并猜测这与本地计算机处理时间的方式相对于 shinyapps.io 服务器处理时间的方式不同有关。尝试以不同的格式存储时间数据,例如字符值。然后在 server.R 中包含将该信息转换为 POSIXlt 值的代码,例如 strptime(time, format = "%F %T")。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-28
    • 1970-01-01
    • 2015-12-26
    • 2020-07-19
    • 1970-01-01
    • 2014-12-04
    • 1970-01-01
    相关资源
    最近更新 更多