-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhands-on_shinydashboard_fd.R
More file actions
89 lines (65 loc) · 2.7 KB
/
hands-on_shinydashboard_fd.R
File metadata and controls
89 lines (65 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
##################################################
# Visualizing Operational Informatics Data Using R
# MEDFINFO 2015
# by Leslie McIntosh & Connie Zabarouskaya
# Hands-on for shinydashboard
##################################################
# # Source Code (step 0)
## app.R ##
library(shiny)
library(shinydashboard)
library(rCharts)
# Data preparation code
# function to convert to POSIXct date format, specifically for line chart
to_jsdate2 <- function(x){
as.numeric(as.POSIXct(as.Date(x), origin="1970-01-01")) * 1000
}
# read in an altered sample of JIRA data
opsdata <- read.csv("data/opsdata.csv")
# change the date columns format to Date
opsdata$created <- as.Date(opsdata$created, format = "%m/%d/%Y %H:%M")
# sort the data by date
opsdata <- opsdata[order(opsdata$created),]
# create a month variable for aggregation
opsdata$created_month <- as.Date(cut(opsdata$created, "month"))
# create a vector with cumulative sum of unique PIs
unique_PIs <- cummax(as.numeric(factor(opsdata$PI_name, levels = unique(opsdata$PI_name))))
# matching cumulative sum of unique PIs to unique months
PI_cumul_growth <- aggregate(unique_PIs, list(Month=opsdata$created_month), max)
# add variable with only new PIs added in each month
PI_cumul_growth$new_pi_num <- c(PI_cumul_growth$x[1], (tail(PI_cumul_growth$x, -1) - head(PI_cumul_growth$x, -1)))
#change the date format to suit rCharts
PI_cumul_growth$date <- to_jsdate2(as.Date(PI_cumul_growth$Month))
# the function handling UI
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody()
)
# in a ui.R file it will look like this:
# dashboardPage(
# dashboardHeader(),
# dashboardSidebar(),
# dashboardBody()
# )
# the function handling server side
server <- function(input, output) { }
# in a server.R file it will look like this:
# shinyServer(
# function(input, output) {}
# )
shinyApp(ui, server)
# This is the canvas you'll use to fill with charts and widgets
# NOTE: this layout is unique to shinydashboard package, however, once you try it
# you are unlikely to go back to the simple layouts of Shiny package
# Follow the steps of the hands-on exercise
# After you complete the training steps, move on to your task.
#################################
# Your task
#################################
# You are given 5 min to try and add a chart and widget on your own.
# Add a histogram chart to this dashboard, in its own box()
# The histogram should visualize distribution of a variable in the opsdata
# Dataset (you can use HoursLogged column to begin with). Use the FrequencyPlot
# As a starter. Next add a selectInput() widget as we have with "Number of Projects"
# With two options: HoursLogged and DaysOpen. Connect the input and the histogram.