rshinyr-dygraphs

Choosing a column in my dataframe to create line chart


My data set has three columns. One column for time, and two other columns for temperature measurements (Temp1, Temp2).

I want to be able to select Temp1 or Temp2 and graph the time series, but I am not sure how to do that in my server.R code. What should go in my dygraph function call?

# This is the server logic for a Shiny web application.
# You can find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com
#

library(shiny)
library(dygraphs)

shinyServer(function(input, output) {

  output$TempData <- renderDygraph({
    data <- switch(input$data,
                   "Temp 1" = Data1$Temp1,
                   "Temp 2" = Data1$Temp2),
    dygraph(data, main = "Temperature Rise Data") %>%

     **I'm not sure what goes in here** 

  })

})

and here is ui.R

# This is the user-interface definition of a Shiny web application.
# You can find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com
#

library(shiny)
library(dygraphs)

shinyUI(fluidPage(

  # Application title
  titlePanel("Temperature Data"),

  # Sidebar with a slider input for number of bins
  sidebarLayout(
    sidebarPanel(
      selectInput("data", label = "Choose a Dataset",
                  choices = c("Temp 1", "Temp 1"),
                  selected = "Temp 1" ))
    ),

    # Show a plot of the generated distribution
    mainPanel(
      dygraphOutput("TempData")
    )
  )
)

Solution

  • From what I can tell, this should give you something along the lines of what you're looking for?

    I'm forcing the coercion of Scan to a Date in order to make it compatible - not sure if this is the best way of doing this, but it will at least allow you to generate basic dygraphs with this data for the moment - you'll probably want to look into formatting the axis further.

    ...
    data <- switch(input$data,
                   "Temp 1" = as.xts(Data1$Temp1, order.by = as.Date(Data1$Scan))
                   "Temp 2" = as.xts(Data1$Temp2, order.by = as.Date(Data1$Scan))
    dygraph(data, main = "Temperature Rise Data")
    ...