A caption
library(ggplot2)
library(vioplot)
## Loading required package: sm
## Package 'sm', version 2.2-5.6: type help(sm) for summary information
library(shiny)
library(plyr)
library(plotly)
##
## Attaching package: 'plotly'
## The following objects are masked from 'package:plyr':
##
## arrange, mutate, rename, summarise
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(ggiraph)
library(shinydashboard)
##
## Attaching package: 'shinydashboard'
## The following object is masked from 'package:graphics':
##
## box
walk <- read.csv("C:/Users/Yvonne/Desktop/HRU/MS Analytics/ANLY 512-90 Data Visualization/Final Project/walk.csv")
##change date format
walk$Date = as.Date(walk$Date,format = "%m/%d/%y")
walk$Steps = as.integer(walk$Steps)
walk$Day = as.factor(walk$Day)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody()
)
server <- function(input, output) { }
#Dashboard header carrying the title of the dashboard
header <- dashboardHeader(title = "ANLY 512 Final Project")
#Sidebar content of the dashboard
sidebar <- dashboardSidebar(
sidebarMenu(
menuItem("The Quantified Self", tabName = "The Quantified Self", icon = icon("dashboard")),
menuItem("Linkedin", icon = icon("send",lib='glyphicon'),
href = "https://www.linkedin.com/in/yvonne-zhao-bba1983a/"),
menuItem("Presented by: Yiwen Zhao")
)
)
frow1 <- fluidRow(
valueBoxOutput("value1")
,valueBoxOutput("value2")
,valueBoxOutput("value3")
)
frow2 <- fluidRow(
box(
title = "Daily Walk Steps by Month-Day"
,status = "primary"
,solidHeader = TRUE
,collapsible = TRUE
,plotOutput("DailyWalk", click = "plot1_click",height = "300px")
)
,box(
title = "Daily Walk Steps by Week-Day"
,status = "primary"
,solidHeader = TRUE
,collapsible = TRUE
,plotOutput("Violin", click = "plot2_click", height = "300px")
)
, box(
verbatimTextOutput("info1")
)
, box(
verbatimTextOutput("info2")
)
)
# combine the two fluid rows to make the body
body <- dashboardBody(frow1, frow2)
#completing the ui part with dashboardPage
ui <- dashboardPage(title = 'My Quantified Self', header, sidebar, body, skin='red')
# create the server functions for the dashboard
server <- function(input, output) {
#some data manipulation to derive the values of KPI boxes
hot.month = walk %>% group_by(Month) %>% summarise(value = mean(Temp)) %>% filter(value==max(value))
max.month = walk %>% group_by(Month) %>% summarise(value = mean(Steps)) %>% filter(value==max(value))
max.day= walk %>% group_by(Day) %>% summarise(value = mean(Steps)) %>% filter(value==max(value))
#creating the valueBoxOutput content
output$value1 <- renderValueBox({
valueBox(
formatC(hot.month$value, digits=0, format="f", big.mark=',')
,paste('Warmest Month (F):', hot.month$Month)
,icon = icon("fire",lib='glyphicon')
,color = "yellow")
})
output$value2 <- renderValueBox({
valueBox(
formatC(max.month$value, digits=0, format="f", big.mark=',')
,paste('Most Active Month:', max.month$Month)
,icon = icon("stats",lib='glyphicon')
,color = "purple")
})
output$value3 <- renderValueBox({
valueBox(
formatC(max.day$value, digits=0, format="f", big.mark=',')
,paste('Most Active Day:', max.day$Day)
,icon = icon("menu-hamburger",lib='glyphicon')
,color = "green")
})
#creating the plotOutput content
output$DailyWalk <- renderPlot({
ggplot(walk) +
geom_bar(mapping = aes(x = Date, y = Steps * 100 / 20000), stat = "identity", colour = "#FF9999", fill = "#FF9999") +
geom_line(mapping = aes(x = Date, y = Temp)) +
geom_point(mapping = aes(x = Date, y = Temp), size = 1, shape = 21, fill = "blue") +
scale_y_continuous(
name = expression("Temperature ("~degree~"F)"),
sec.axis = sec_axis(~ . * 20000 / 100 , name = "Daily Walk (steps)"),
limits = c(0, 100))
})
output$info1 <- renderText({paste0("Temperature: ", input$plot1_click$y)
})
output$Violin <- renderPlot({
ggplot(walk, aes(x = factor(Day, level = c('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun')), y=Steps))+geom_violin(fill="gold") +xlab("Day") +stat_summary(fun.y = "mean", geom = "point", size = 4, color = "brown")
})
output$info2 <- renderText({paste0("Steps:", input$plot2_click$y)
})
}
shinyApp(ui, server)