Skip to content

Commit

Permalink
Fixed #15 Fixed #1 #13 #7
Browse files Browse the repository at this point in the history
  • Loading branch information
dhuy228 committed Sep 10, 2019
1 parent 3015b44 commit 4253e8e
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 19 deletions.
131 changes: 129 additions & 2 deletions cie-dashboards/server.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
## server.R ##
## CIE Dashboards

# libraries
library(shiny)
library(shinydashboard)
library(ggplot2)
library(ggthemes)
library(tidyr)
library(reshape2)
library(tidyverse)
library(readxl)
library(dplyr)
library(plotly)

# Import data
overviewData <- read_csv("../data/overview.csv")

# Define server logic required to draw a histogram
server <- function(input, output) {

Expand All @@ -11,6 +26,35 @@ server <- function(input, output) {
filter(year == input$baseYear)
return(df)
})
overviewPlot_df <- reactive({
df <- overviewData %>%
select(ID,year) %>%
distinct() # Remove duplicates
return(df)
})
facultyPlot_df <- reactive({
df <- overviewData %>%
filter(year %in% c(input$baseYear, input$compareYears)) %>%
select(ID,year,`Owner of Major/Spec/Module`) %>%
distinct() # Remove duplicates
return(df)
})
programmePlot_df <- reactive({
df <- overviewData %>%
filter(year %in% c(input$baseYear, input$compareYears)) %>%
filter(programme %in% c("CIE Participant", "Velocity Participant", "Unleash Space Participant", "Unleash Space Access", "Equipment Training Participant" )) %>%
select(ID,year,programme) %>%
distinct() # Remove duplicates
return(df)
})
heatmap_df <- reactive({
df <- overviewData %>%
filter(year == input$baseYear) %>%
filter(programme %in% c("CIE Participant", "Velocity Participant", "Unleash Space Participant", "Unleash Space Access", "Equipment Training Participant" )) %>%
select(ID,`Owner of Major/Spec/Module`, programme) %>%
distinct() # Remove duplicates
return(df)
})


# Info boxes
Expand All @@ -33,10 +77,11 @@ server <- function(input, output) {
output$repeatParticipant <- renderInfoBox(
{
repeat_participant <- infoOverview_r() %>% group_by(ID) %>% filter(row_number()==2) %>% distinct(`ID`) %>% nrow()
unique_particpant <- infoOverview_r() %>% distinct(`ID`) %>% count()
print(repeat_participant)
infoBox(
"Repeat participant", #m vlaue here, icon= icon(), color=
repeat_participant
paste0(repeat_participant, " (", round(repeat_participant*100/unique_particpant,1),"%)")
)
})
output$onetimeParticipant <- renderInfoBox(
Expand All @@ -47,5 +92,87 @@ server <- function(input, output) {
onetime_participant
)
})


# Overview plot
output$totalPlot <- renderPlotly({
p <- overviewPlot_df() %>%
select(ID,year) %>%
group_by(year) %>%
summarise(count=n()) %>%
ggplot() +
geom_line(aes(x=year,y=count)) +
ggtitle("Total participants by year") +
theme_minimal() + guides(fill=FALSE, color=FALSE) + labs(y="", x = "") + scale_color_continuous_tableau()

ggplotly(p)
})

output$uniquePlot <- renderPlotly({
p <- overviewPlot_df() %>%
select(ID,year) %>%
group_by(year) %>%
distinct(ID) %>%
summarise(count=n()) %>%
ggplot() +
geom_line(aes(x=year,y=count)) +
ggtitle("Unique participants by year") +
theme_minimal() + guides(fill=FALSE, color=FALSE) + labs(y="", x = "") + scale_color_continuous_tableau()
#+ annotate("segment", xmin=(input$baseYear - 0.5), xmax = (input$baseYear + 0.5), alpha= .2)
ggplotly(p)
})

# Faculty
output$facultyN <- renderPlotly({
facultyPlot_df() %>%
group_by(`Owner of Major/Spec/Module`,year) %>%
summarise(count=n()) %>%
ggplot() +
geom_bar(aes(x=reorder(`Owner of Major/Spec/Module`, count), count, fill=factor(year)), stat="identity", position = "dodge") +
guides(fill=FALSE) +
coord_flip() +
ggtitle("Faculty split overall") +
theme_minimal() +
scale_fill_tableau() + labs(x="", y="")
})

# Programme
output$programmeN <- renderPlotly({
programmePlot_df() %>%
group_by(`year`, `programme`) %>%
summarise(count=n()) %>%
ggplot() +
geom_bar(aes(x=reorder(`programme`, count), count, fill=factor(year)), stat="identity", position = "dodge") +
guides(fill=FALSE) +
coord_flip() +
ggtitle("Programme split overall") +
theme_minimal() +
#labs(x="", y="", title="Programme split overall") +
#theme(plot.title = element_text(hjust=0)) +
scale_fill_tableau()
})

# Programme split by faculty
# Create dataframe for heatmap
output$programmeFaculty <- renderPlotly({
p <- heatmap_df() %>%
group_by(`programme`,`Owner of Major/Spec/Module`) %>%
summarise(count=n()) %>%
complete(`Owner of Major/Spec/Module` = unique(df_stud$`Owner of Major/Spec/Module`)) %>%
ggplot(aes(`Owner of Major/Spec/Module`,`programme`)) +
geom_tile(aes(fill=count)) +
guides(color=FALSE) +
#ggtitle("Programme split by faulcuty") +
scale_fill_gradient_tableau(na.value = "grey") +
#scale_x_discrete(position="top") +
#scale_fill_gradient(low="white", high = "steelblue", na.value="grey80") +
#coord_fixed(ratio=.5) +
theme_minimal() +
theme(axis.text.x = element_text(angle = 30, hjust=0), axis.ticks = element_blank()) +
labs(x="", y="")
ggplotly(p) %>%
layout(
xaxis = list(showgrid = FALSE, side="top", scaleanchor="y", constrain="domain", zeroline=FALSE),
yaxis = list(showgrid = FALSE, zeroline=FALSE)
)
})
}
57 changes: 41 additions & 16 deletions cie-dashboards/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ui <- dashboardPage(
# Menu
dashboardSidebar(
sidebarMenu(

#style = "position: fixed; width: inherit",
# Dashboard menu
menuItem("Overview", tabName = "overview", icon = icon("fas fa-square")),
menuItem("Programme", tabName = "programme", icon = icon("fas fa-square")),
Expand All @@ -37,17 +37,17 @@ ui <- dashboardPage(
selectInput(
"baseYear",
"Base year",
choices = unique(overviewData$year),
choices = sort(unique(overviewData$year), decreasing = TRUE),
selected = "2017",
multiple = FALSE

),
selectInput(
selectizeInput(
"compareYears",
"Comparing years",
choices = unique(overviewData$year),
choices = sort(unique(overviewData$year), decreasing = TRUE),
multiple = TRUE,
selectize = TRUE
options = list(placeholder="Select year..", plugins=list("remove_button"))
)
)
),
Expand All @@ -59,28 +59,53 @@ ui <- dashboardPage(
# Overview
tabItem(
tabName = "overview",
h2("Overview"),

h4("Overview"),
# Info boxes
fluidRow(
infoBoxOutput("totalParticipant"),
infoBoxOutput("uniqueParticipant"),
infoBoxOutput("repeatParticipant"),
infoBoxOutput("onetimeParticipant")
infoBoxOutput("totalParticipant",width=3),
infoBoxOutput("uniqueParticipant",width=3),
infoBoxOutput("repeatParticipant",width=3),
infoBoxOutput("onetimeParticipant",width=3)
),

# Faculty split overall
# Overview chart
fluidRow(
column(6,
tabItem(tabName="Overview plot", width=NULL,
plotlyOutput("totalPlot", height = "300px"))
),
column(6,
tabItem(tabName="Overview plot", width=NULL,
plotlyOutput("uniquePlot", height = "300px"))
)
),

# Faculty split by programme
h4("Programme split by faculty"),
fluidRow(
column(12,
plotlyOutput("programmeFaculty", height = "600px")
)
),
# Programme split overall

# Faculty split overall
h4("Faculty split"),
fluidRow(
column(12,
plotlyOutput("facultyN", height = "600px")
)

),
# Faculty split by programme
# Programme split overall
h4("Programme split"),
fluidRow(

column(12,
plotlyOutput("programmeN", height = "600px")
)

)

),

# Programme
Expand Down
3 changes: 2 additions & 1 deletion data-management.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ df <- merge(x=partProg, y=partInfo, by="ID", all.x = TRUE)
df_stud <- df %>%
filter(!is.na(`Acad Prog`)) %>%
filter(grepl("^\\d{4}", programme)) %>%
mutate(year=substring(`programme`,0,4), programme=substring(`programme`,6))
mutate(year=substring(`programme`,0,4), programme=substring(`programme`,6)) %>%
distinct()
head(df_stud,10)
```

Expand Down

0 comments on commit 4253e8e

Please sign in to comment.