Skip to content

Instantly share code, notes, and snippets.

@loiyumba
Created May 16, 2016 04:11
Show Gist options
  • Save loiyumba/cbe4830d8cc99e4161ac7183fe16b30f to your computer and use it in GitHub Desktop.
Save loiyumba/cbe4830d8cc99e4161ac7183fe16b30f to your computer and use it in GitHub Desktop.
Dashboard for school students
require(shiny)
require(shinydashboard)
require(ggplot2)
require(ggthemes)
require(magrittr)
sample <- read.csv("new_sample4.csv", stringsAsFactors = FALSE)
header <- dashboardHeader(title = "XYZ School Student Dashboard", titleWidth = 370)
body <- dashboardBody(
tags$head(tags$style(HTML('
.main-header .logo {
font-family: "Georgia", Times, "Times New Roman", serif;
font-weight: bold;
font-size: 20px;
}
'))),
fluidRow(
column(width = 9,
valueBox(2010, "Year of Establishment", icon = icon("building"), width = NULL),
valueBoxOutput("totalStudent", width = NULL),
box(title = "Selected Student", width = NULL, solidHeader = TRUE, status = "info",
textOutput("summary1"),
textOutput("summary2"),
textOutput("summary3"),
textOutput("summary4")),
box(title = "Selected student marks card", status = "info", width = NULL, solidHeader = TRUE, collapsible = TRUE,
tableOutput("table")),
box(title = "Selected student marks visualization", status = "info", width = NULL, solidHeader = TRUE, collapsible = TRUE,
plotOutput("plot")),
box(title = "Class students ranking by percentage achieved", status = "info", width = NULL, solidHeader = TRUE, collapsible = TRUE,
tableOutput("percent")),
box(title = "Class students ranking visualization", status = "info", width = NULL, solidHeader = TRUE, collapsible = TRUE,
plotOutput("rankplot")),
box(title = "Selected student periodic tests comparison", status = "info", width = NULL, solidHeader = TRUE, collapsible = TRUE,
plotOutput("periodic")),
box(title = "Selected student term exams comparison", status = "info", width = NULL, solidHeader = TRUE, collapsible = TRUE,
plotOutput("term"))
),
column(width = 3,
box(title = "Select", background = "blue" , width = NULL,
selectInput("class", "Class", unique(sample$Class)),
selectInput("name", "Name", unique(sample$Name)),
selectInput("exams", "Exams", choices = c("1st Periodic Test", "1st Term", "2nd Periodic Test",
"2nd Term", "3rd Periodic Test", "4th Periodic Test",
"Final")),
br(),"Note:", br(),
"The first box is the establishment year of the school.", br(), br(),
"The second box is the number of student in a particular class.", br(), br(),
"The third box 'Selected Student' is a short summary of the selected student from the select option.", br(), br(),
"The fourth box 'Selected student marks card' is the marks card of the test/exam selected for the selected student.", br(), br(),
"The fifth box 'Selected student marks visualization' is the extension of 'Selected student marks card' in
visualization. Here, the red line in the bar denotes the pass mark for that particular subject and the black
line denotes the class average for that particular subject. The marks got by student for every subject
is listed above the bar.", br(), br(),
"The sixth box 'Class student ranking by percentage achieved' is the overall ranking of the students in
a class for the selected test/exam.", br(), br(),
"The seventh box 'Class students ranking visualization' is the extension of 'Class student ranking by percentage
achieved' in visualization. Here, the vertical black dotted line denotes the average percentage of the class
for the selected test/exam.", br(), br(),
"The eight box 'Selected student periodic tests comparison' is the visualization of trend shown by the selected
student in all the periodic tests during an academic year.", br(), br(),
"The ninth box 'Selected student term exams comparison' is the visualization of trend shown by the selected
student in all the term exams during an academic year."
)
)
)
)
ui <- dashboardPage(skin = "blue",
header,
dashboardSidebar(disable = TRUE),
body
)
server <- function(input, output, session){
studentName <- reactive({
paste("Student Name:", input$name)
})
output$summary1 <- renderText({
studentName()
})
output$summary2 <- renderText({
paste("Class: ", input$class)
})
examsName <- reactive({
paste("Examination: ", input$exams)
})
output$summary3 <- renderText({
examsName()
})
getdataset <- reactive({
dataset <- sample[sample$Class == input$class & sample$Name == input$name & sample$Examination == input$exams, ]
dataset[, c("Date", "Subject", "Max_Mark", "Pass_Mark", "Obtain_Mark", "Class_Average",
"Subject_Percentage")]
})
observe({
classInput <- input$class
updateSelectInput(session, "name", choices = sample$Name[sample$Class == classInput])
})
output$table <- renderTable({
getdataset()
}, include.rownames = FALSE)
percentdataset <- reactive({
dat <- sample[sample$Class == input$class & sample$Examination == input$exams, ]
percent_table <- dat
percent_table <- percent_table[!duplicated(percent_table$Name), ]
percent_table <- percent_table[, c("Name", "Exam_Percentage")]
percent_table <- percent_table[order(-percent_table$Exam_Percentage), ]
})
observe({
classinput <- input$class
updateSelectInput(session, "examination", choices = sample$Examination[sample$Class == classinput])
})
output$percent <- renderTable({
percentdataset()
}, include.rownames = FALSE)
getdataset2 <- reactive({
dataset <- sample[sample$Class == input$class & sample$Name == input$name & sample$Examination == input$exams, ]
})
observe({
classInput2 <- input$class
updateSelectInput(session, "name", choices = sample$Name[sample$Class == classInput2])
})
summary4 <- reactive({
rankdata <- getdataset2()
rankdata <- rankdata[!duplicated(rankdata$Name), ]
rankdata <- rankdata[, c("Name","Exam_Percentage")]
paste("Percentage: ", rankdata$Exam_Percentage)
})
output$summary4 <- renderText({
summary4()
})
plotInput <- reactive({
df <- getdataset()
df <- transform(df, Subject = reorder(Subject, -Obtain_Mark))
ggplot(df, aes(x = Subject, y = Obtain_Mark)) +
theme_pander() +
geom_bar(stat = "identity", fill = "#006699") +
geom_text(aes(label = Obtain_Mark),vjust = -0.4) +
geom_errorbar(data = getdataset(),
aes(y = Class_Average, ymax = Class_Average,
ymin = Class_Average), colour = "#000000") +
geom_errorbar(data = getdataset(),
aes(y = Pass_Mark, ymax = Pass_Mark,
ymin = Pass_Mark), colour = "red") +
labs(title = paste(input$name,"'s", input$exams, "marks"), x = "", y = "Marks") +
theme(axis.text=element_text(size=10, face = "bold")
)
})
output$plot <- renderPlot({
print(plotInput())
})
rankplotInput <- reactive({
df2 <- percentdataset()
df2 <- df2[!duplicated(df2$Name), ]
df2 <- df2[, c("Name", "Exam_Percentage")]
df2 <- df2[order(-df2$Exam_Percentage), ]
ggplot(df2, aes(x = reorder(Name, Exam_Percentage), y = Exam_Percentage)) +
theme_pander() +
geom_bar(stat = "identity", fill = "#006699") +
coord_flip() +
geom_text(aes(label = Exam_Percentage), hjust = -0.4) +
labs(title = paste("Class", input$class,"'s", input$exams, "percentage ranking"), x = "", y = "Percentage") +
ylim(0, 100) +
geom_hline(yintercept = mean(df2$Exam_Percentage), colour = "black", linetype = "dashed",
size = 1) +
theme(axis.text=element_text(size=10, face = "bold"))
})
output$rankplot <- renderPlot({
print(rankplotInput())
})
periodicTest <- reactive({
student <- subset(sample, Name == input$name)
student <- subset(student, Examination == "1st Periodic Test" | Examination == "2nd Periodic Test" | Examination == "3rd Periodic Test")
ggplot(student, aes(x = Subject, y = Subject_Percentage, fill = Examination)) +
geom_bar(stat = "identity", position = position_dodge(), colour = "black") +
scale_fill_manual(values = c("#d6e0f5", "#5b82d7", "#234590")) +
theme_pander() +
labs(title = paste(input$name,"'s periodic tests trend"), x = "", y = "Subject Percentage") +
theme(axis.text=element_text(size=10, face = "bold"))
})
output$periodic <- renderPlot({
print(periodicTest())
})
finalTerm <- reactive({
termFinal <- subset(sample, Name == input$name)
termFinal <- subset(termFinal, Examination == "1st Term" | Examination == "2nd Term" | Examination == "Final")
ggplot(termFinal, aes(x = Subject, y = Subject_Percentage, fill = Examination)) +
geom_bar(stat = "identity", position = position_dodge(), colour = "black") +
scale_fill_manual(values = c("#d6e0f5", "#5b82d7", "#234590")) +
theme_pander() +
labs(title = paste(input$name,"'s term exams trend"), x = "", y = "Subject Percentage") +
theme(axis.text=element_text(size=10, face = "bold"))
})
output$term <- renderPlot({
print(finalTerm())
})
#studentCount <- reactive({
#total <- subset(sample, Class == input$class)
#count <- length(unique(total$Name))
#count
#})
output$totalStudent <- renderValueBox({
total <- subset(sample, Class == input$class)
count <- length(unique(total$Name))
valueBox(
paste(count, "Students"), paste("Class", input$class) ,icon = icon("user"),
color = "light-blue")
})
}
shinyApp(ui, server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment