R Shiny server.R reactive time/date 带有变化轴的滑块
R Shiny server.R reactive time/date slider with changing axis
我有一个包含 5 个参数和一个 date/time 列的数据框。我希望能够使用下拉菜单绘制参数(即列),并使用滑块移动 date/time。 server.R 我遇到了严重的问题。 date/time 表示数据随下拉参数变化的滑块。下面的示例数据,server.R 缺少关键元素
LAT=rnorm(10)
LONG=rnorm(10)
DO=rnorm(10)
SP=rnorm(10)
TMP=rnorm(10)
DateTime=as.POSIXct(c("2016-04-18 10:30:00 ",
"2016-04-18 10:30:00 ", "2016-04-18 10:31:00 ",
"2016-04-18 10:31:00 ", "2016-04-18 10:32:00 ",
"2016-04-18 10:32:00 ",
"2016-04-18 10:33:00 ", "2016-04-18 10:33:00 ",
"2016-04-18 10:34:00 ", "2016-04-18 10:34:00"))
DATA=data.frame(cbind(LAT,LONG,DO,SP,TMP,DateTime))
DATA$DateTime=as.POSIXct(DateTime)
ui=(pageWithSidebar(
headerPanel('DATA Comparison'),
sidebarPanel(
selectInput('xcol', 'X Variable', names(DATA)),
selectInput('ycol', 'Y Variable', names(DATA),
selected=names(DATA)[[3]]),
sliderInput('dtime', 'Date Time',min(DATA$DateTime),max(DATA$DateTime),
min(DATA$DateTime),step=60, timeFormat= "%F %T")
),
mainPanel(
plotOutput('plot1')
)
))
server=(function(input, output, session) {
selectedData = reactive({
DATA[ , c(input$xcol, input$ycol)]
})
参见下面的示例
server=(function(input, output, session) {
output$plot1 <- renderPlot({
selected <- DATA[DATA$DateTime==input$dtime, ]
plot(selected[[input$xcol]], selected[[input$ycol]])
})
})
我有一个包含 5 个参数和一个 date/time 列的数据框。我希望能够使用下拉菜单绘制参数(即列),并使用滑块移动 date/time。 server.R 我遇到了严重的问题。 date/time 表示数据随下拉参数变化的滑块。下面的示例数据,server.R 缺少关键元素
LAT=rnorm(10)
LONG=rnorm(10)
DO=rnorm(10)
SP=rnorm(10)
TMP=rnorm(10)
DateTime=as.POSIXct(c("2016-04-18 10:30:00 ",
"2016-04-18 10:30:00 ", "2016-04-18 10:31:00 ",
"2016-04-18 10:31:00 ", "2016-04-18 10:32:00 ",
"2016-04-18 10:32:00 ",
"2016-04-18 10:33:00 ", "2016-04-18 10:33:00 ",
"2016-04-18 10:34:00 ", "2016-04-18 10:34:00"))
DATA=data.frame(cbind(LAT,LONG,DO,SP,TMP,DateTime))
DATA$DateTime=as.POSIXct(DateTime)
ui=(pageWithSidebar(
headerPanel('DATA Comparison'),
sidebarPanel(
selectInput('xcol', 'X Variable', names(DATA)),
selectInput('ycol', 'Y Variable', names(DATA),
selected=names(DATA)[[3]]),
sliderInput('dtime', 'Date Time',min(DATA$DateTime),max(DATA$DateTime),
min(DATA$DateTime),step=60, timeFormat= "%F %T")
),
mainPanel(
plotOutput('plot1')
)
))
server=(function(input, output, session) {
selectedData = reactive({
DATA[ , c(input$xcol, input$ycol)]
})
参见下面的示例
server=(function(input, output, session) {
output$plot1 <- renderPlot({
selected <- DATA[DATA$DateTime==input$dtime, ]
plot(selected[[input$xcol]], selected[[input$ycol]])
})
})