潜入我的第一个有光泽的App ......
我在帖子底部有25个GPS位置,head
位于下方。日期格式为as.POSIXct
head(dat)
GPSUTMNorthing GPSUTMEasting PosiGMT
1 4947787 600201 2013-02-09 00:00:00
2 4947945 600910 2013-02-09 06:00:00
5 4947957 600911 2013-02-10 00:00:00
6 4947954 600907 2013-02-10 06:00:00
8 4947797 601052 2013-02-10 18:00:00
9 4947835 601038 2013-02-11 00:00:00
下面的UI
和server
个对象可用于制作shinyApp
,用于绘制与sliderInput
上所选日期对应的位置。我不想仅绘制特定日期的位置,而是希望在sliderInput
上向前移动日期时依次添加位置。通过这种方式,第一个日期的点被保持为sliderInput
顺序向前移动。
任何建议都将不胜感激。
library(ggplot2)
library(shiny)
ui <- fluidPage(
titlePanel("GPS Data Summary"),
sliderInput(inputId = "Order",
label = "Sequance of Observations",
min = as.Date(min(dat$PosiGMT)), max = as.Date(max(dat$PosiGMT)), value = as.Date(min(dat$PosiGMT))),
plotOutput("PointPlot")
)
server <- function(input, output) {
output$PointPlot <- renderPlot({
p <- ggplot(dat[as.Date(dat$PosiGMT) == input$Order ,], (aes(x = GPSUTMEasting , y = GPSUTMNorthing ))) +
geom_point() + geom_path() +
xlim( min(dat$GPSUTMEasting), max(dat$GPSUTMEasting))+
ylim( min(dat$GPSUTMNorthing), max(dat$GPSUTMNorthing))
print(p)
})
}
shinyApp(ui = ui, server = server)
以下可重复数据
dat <- structure(list(GPSUTMNorthing = c(4947787L, 4947945L, 4947957L,
4947954L, 4947797L, 4947835L, 4947825L, 4947784L, 4947842L, 4947839L,
4947789L, 4947807L, 4947839L, 4947845L, 4947779L, 4947824L, 4947824L,
4947772L, 4947824L, 4947821L, 4947816L, 4947809L, 4947840L, 4947829L,
4947820L), GPSUTMEasting = c(600201L, 600910L, 600911L, 600907L,
601052L, 601038L, 601031L, 601066L, 600998L, 600995L, 601058L,
601038L, 600987L, 601071L, 601016L, 601002L, 601003L, 601003L,
600917L, 600916L, 600918L, 600923L, 600985L, 600980L, 600914L
), PosiGMT = structure(c(1360393200, 1360414800, 1360479600,
1360501200, 1360544400, 1360566000, 1360587600, 1360630800, 1360652400,
1360674000, 1360695600, 1360717200, 1360738800, 1360803600, 1360825200,
1360846800, 1360868400, 1360890000, 1360911600, 1360933200, 1360954800,
1360976400, 1360998000, 1361019600, 1361041200), class = c("POSIXct",
"POSIXt"), tzone = "")), .Names = c("GPSUTMNorthing", "GPSUTMEasting",
"PosiGMT"), row.names = c(1L, 2L, 5L, 6L, 8L, 9L, 10L, 12L, 13L,
14L, 15L, 16L, 17L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L,
29L, 30L, 31L), class = "data.frame")
答案 0 :(得分:2)
你几乎拥有它,这不是一个闪亮的问题,而是一个子集。
变化:
ggplot(dat[as.Date(dat$PosiGMT) == input$Order ,]
到
ggplot(dat[as.Date(dat$PosiGMT) <= input$Order ,]
我认为这是你想要的行为