简体   繁体   中英

R Shiny server.R reactive time/date slider with changing axis

I have a data frame with 5 parameters plus a date/time column. I would like to be able to plot parameters (ie columns) against one another using drop downs, and use a slider to move date/time. I'm having serious issues with the server.R. date/time slider representing the data as the drop down parameters change. Sample Data Below, server.R is missing key elements

      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)]
  })

See the example below

server=(function(input, output, session) {

    output$plot1 <- renderPlot({
        selected <- DATA[DATA$DateTime==input$dtime, ]
        plot(selected[[input$xcol]], selected[[input$ycol]])
    })

})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM