Shiny Application for an Activity Monitoring Device

JGG
15 April 2017

OVERVIEW

This project will show you an application done in Shiny that summarizes data from an activity monitoring device such fitbit and other similar devices.

The application features will be revealed later.

SAMPLE DATASET

For the dataset, uniform random numbers are generated wherein minimum and maximum number of steps taken per 5-minute interval were from the summary of the activity dataset from the course website:activity data.

interval = seq(from = 0, to = 2355, by = 5)
set.seed(1)
AllAve = runif(472,0,250)
set.seed(2)
WeekendsAve = runif(472,0,250)
set.seed(3)
WeekdaysAve = runif(472,0,250)
NewDataSet = data.frame(interval, AllAve,WeekendsAve,WeekdaysAve)
NewDataSetHead = head(NewDataSet,10)
head(NewDataSet,5)
  interval    AllAve WeekendsAve WeekdaysAve
1        0  66.37717    46.22056    42.01038
2        5  93.03097   175.59351   201.87910
3       10 143.21334   143.33158    96.23559
4       15 227.05195    42.01298    81.93358
5       20  50.42048   235.95983   150.52517

Shiny Application Code: ui.R

library(shiny)
shinyUI(fluidPage(
    headerPanel("Shiny Application for an Activity Monitoring Device"),
      sidebarPanel(
          sliderInput('interval1', 'Set Minimum Interval',value = 0, min = 0, max = 2500, step=5),
          sliderInput('interval2', 'Set Maximum Interval',value = 2500, min = 0, max = 2500, step=5),
          h3("Select Days of the Week:"),
          checkboxInput("All", "All 7 Days", value = TRUE),
          checkboxInput("Weekdays", "Weekdays", value = TRUE),
          checkboxInput("Weekends", "Weekends", value = TRUE)
      ),
      mainPanel(
          tabsetPanel(
              tabPanel("Plot",
              h3("Plot of the Average Number of Steps Taken per 5-Minute Interval"),
              verbatimTextOutput("warning"),
              plotOutput('lineGraph',click = "plot_click", width = "100%"),
              h4("Note: Click the plot to show values below."),
              verbatimTextOutput("info")
          ),
          tabPanel("Summary",
              h3("Activity Data Set - Average Number of Steps per 5-Minute Interval"),
              tableOutput("summary"))
          )
      )
))

Shiny Application Code: server.R

library(shiny)
shinyServer(function(input,outpu){})
output$warning = renderText({
      minInterval <- input$interval1
      maxInterval <- input$interval2
      ifelse(minInterval>maxInterval, "WARNING: Minimum interval should be lower than Maximum!", "VALID Minimum and Maximum Interval")
})
output$summary = renderTable(NewDataSetHead)
output$lineGraph <- renderPlot({
      minInterval <- input$interval1
      maxInterval <- input$interval2
      x1 = NewDataSet$interval
      y1 = NewDataSet$AllAve
      y2 = NewDataSet$WeekdaysAve
      y3 = NewDataSet$WeekendsAve
      plot(0,0,type="l",col="blue", xlim=c(minInterval,maxInterval),
    ylim=c(0,260), xlab="5-minute interval",ylab="average steps")
      if(input$All){
          lines(x1,y1,type="l",col="blue")
      }
      if(input$Weekdays){
          lines(x1,y2,type="l",col="green")
      }
      if(input$Weekends){
          lines(x1,y3,type="l",col="orange")
      }
      legend(1500,250,c("All Days","Weekdays","Weekends"),lty=c(1,1,1), col=c("blue","green","orange"))
},
      height = 400, width = 600)

 output$info <- renderText({
      paste0("Interval=", input$plot_click$x, "\nAverageSteps=", input$plot_click$y)
})
})

APPLICATION FEATURES

PLOT Tab: Plot of the Average Number of Steps Taken per 5-Minute Interval

  • Minimum and maximum interval can be set
  • With warning sign if entry in bullet 1 is invalid
  • Days of the week to be displayed can be selected
  • Plots are interactive when clicked

SUMMARY Tab: Summary Table of the Dataset

  • Display the first 10 rows of the data frame

CLICK HERE CLICK HERE to try the App!

Below is the PREVIEW

some caption