JGG
15 April 2017
This project will show you an application done in Shiny that summarizes data from an activity monitoring device such fitbit and other similar devices.
SAMPLE DATASET
For the dataset, uniform random numbers are generated wherein minimum and maximum average number of steps taken per 5-minute interval were from the summary of the activity dataset from the course website:activity data.
Here is the PREVIEW and TRY the APP later…
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"))
)
)
))
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)
})
})
PLOT Tab: Plot of the Average Number of Steps Taken per 5-Minute Interval
SUMMARY Tab: Summary Table of the Dataset
CLICK HERE CLICK HERE to try the App!