forked from govau/GAlileo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathagencycomparison.R
126 lines (107 loc) · 3.82 KB
/
agencycomparison.R
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
if (!exists("agency")){
agency <- read.csv("agency-1000plus.csv", stringsAsFactors = FALSE)[,-1]
}
if (!exists("all_agencies")){
all_agencies <- read_xlsx("hostnames.xlsx", sheet = 1, col_names = F, col_types = "text")
colnames(all_agencies) <- c("hostnames")
}
if (!exists("large_agencies")){
large_agencies <- read_xlsx("hostnames.xlsx", sheet = 2, col_names = F, col_types = "text")
colnames(large_agencies) <- c("hostnames")
}
if (!exists("med_agencies")){
med_agencies <- read_xlsx("hostnames.xlsx", sheet = 3, col_names = F, col_types = "text")
colnames(med_agencies) <- c("hostnames")
}
if (!exists("small_agencies")){
small_agencies <- read_xlsx("hostnames.xlsx", sheet = 4, col_names = F, col_types = "text")
colnames(small_agencies) <- c("hostnames")
}
agencyComparison <- tabPanel(
"Agency Comparison", # Sidebar with a slider input for number of bins
# Sidebar layout with input and output definitions ----
sidebarLayout(
# Sidebar panel for inputs ----
sidebarPanel(
# Input: Selector for choosing dataset ----
selectInput(
inputId = "agencies",
label = "Choose an agency:",
choices = c("dta.gov.au", "humanservices.gov.au", "casa.gov.au")
),
selectInput(
inputId = "groups",
label = "Compare with:",
choices = c("small", "medium", "large", "all"),
),
width = 3)
,
# Main panel for displaying outputs ----
main = mainPanel(
# Output: Formatted text for caption ----
h3(textOutput("ac_caption", container = span)),
# Output: Verbatim text for data summary ----
verbatimTextOutput("ac_summary"),
# Output: HTML table with requested number of observations ----
fluidRow(
splitLayout(cellWidths = c("50%", "50%"), plotOutput("view1"), plotOutput("view2"))
)
)
)
)
agencycomparison_server <- function (input, output) {
# Return the requested dataset ----
# By declaring datasetInput as a reactive expression we ensure
# that:
#
# 1. It is only called when the inputs it depends on changes
# 2. The computation and result are shared by all the callers,
# i.e. it only executes a single time
group_filter <- reactive({
switch(input$groups,
"small" = small_agencies$hostnames,
"medium" = med_agencies$hostnames,
"large"= large_agencies$hostnames,
"all" = all_agencies$hostnames)})
datasetInput <- reactive({
agency1 <- filter(agency, hostname == input$agencies) %>%
group_by(sourceurl) %>%
arrange(desc(tot_source))
})
DatasetCompare <- reactive({
agency <- filter(agency, hostname %in% group_filter()) %>%
group_by(sourceurl) %>%
arrange(desc(tot_source))
})
output$ac_caption <- renderText({
paste("Comparing referral sources from",input$agencies, " with ", input$groups, "agencies")
})
output$view1 <- renderPlot({
datasetInput() %>%
top_n(5) %>%
ggplot(aes(x="", y=tot_source, fill=sourceurl)) +
geom_bar(width = 1, stat = "identity")+
coord_polar("y", start = 0) +
ylab(NULL)+
theme(axis.text = element_blank(),
axis.ticks = element_blank(),
panel.grid = element_blank()) +
ggtitle("Single Agency referal sources") +
theme(legend.position = "none")
})
output$view2 <- renderPlot({
DatasetCompare() %>%
group_by(sourceurl) %>%
top_n(5) %>%
ggplot(aes(x="", y=tot_source, fill = sourceurl)) +
geom_bar(width = 1, stat = "identity")+
coord_polar("y", start = 0)+
ylab(NULL)+
theme(axis.text = element_blank(),
axis.ticks = element_blank(),
panel.grid = element_blank()) +
ggtitle("Cohort Agencies referal sources") +
theme(legend.position = "none")
})
}
shinyApp(ui = agencyComparison, server = agencycomparison_server)