Skip to content

Instantly share code, notes, and snippets.

@daranzolin
Created May 13, 2016 15:12
Show Gist options
  • Save daranzolin/06e32c46b1e4e222e96f90c63e53a281 to your computer and use it in GitHub Desktop.
Save daranzolin/06e32c46b1e4e222e96f90c63e53a281 to your computer and use it in GitHub Desktop.
library(tidyr)
library(ggplot2)
library(dplyr)
library(shiny)
library(shinythemes)
library(readr)
library(plotly)
ui <- fluidPage(theme = shinytheme("united"),
titlePanel("Evaluation Review Application"),
sidebarLayout(
sidebarPanel(
selectInput("teacher", "Select Teacher:", choices = teachers, selected = "Teacher A"),
conditionalPanel(condition = "input.tabs==1",
sliderInput("slider", "Binwidth:", min = 1, max = 20, value = 10, step = 5),
checkboxInput("groupdatahist", "Group Data", FALSE)
),
conditionalPanel(condition = "input.tabs==2",
checkboxInput("groupdatadrops", "Group Data", FALSE)
),
conditionalPanel(condition = "input.tabs==3",
tags$p("The selected teacher is the green dot. Teacher Rating is calculated from the evaluation responses. \nIf every student marked 'Strongly Agree', the teacher would have a score of 5. \n If every student marked 'Strongly Disagree, the teacher would have a score of 1."))
),
mainPanel(
fluidRow(
column(width = 9,
tabsetPanel(id = "tabs",
tabPanel("Grades", value = 1, plotlyOutput("grades_hist")),
tabPanel("Drop Rates", value = 2, dataTableOutput("droprates")),
tabPanel("Teacher Ratings", value = 3, plotOutput("dotplot")),
tabPanel("Which Activities Enhanced Your Learning?", value = 4, tableOutput("enhanced")),
tabPanel("If you Could Change One Thing?", value = 5, tableOutput("change"))
)
)
),
fluidRow(h3("Course Evaluation Responses"),
column(width = 9,
plotOutput("evalplots")
)
)
)
)
)
server <- function(input, output) {
output$evalplots <- renderPlot({
eval_response_data %>%
group_by(Teacher, Question, Response) %>%
tally() %>%
filter(Teacher == input$teacher) %>%
mutate(Response = factor(Response,
levels = c("Strongly Agree", "Somewhat Agree", "Neither Agree nor Disagree", "Somewhat Disagree", "Strongly Disagree"))) %>%
ggplot(aes(Response, n)) +
geom_bar(stat = "identity", fill = "lightgreen", color = "black") +
facet_grid(~Question) +
labs(x = "", y = "") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1, size = 12))
})
output$droprates <- renderDataTable({
if (input$groupdatadrops == TRUE) {
all_data %>%
group_by(Teacher) %>%
filter(Option == "Premium", RegDate > "2015-07-01") %>%
summarize(`Drop Rate` = round(mean(GRADE %in% drop_filters), 2),
Enrolls = n(),
Drops = sum(GRADE %in% drop_filters)) %>%
arrange(desc(`Drop Rate`))
} else {
all_data %>%
group_by(Teacher, Course) %>%
filter(Option == "Premium", RegDate > "2015-07-01") %>%
summarize(`Drop Rate` = round(mean(GRADE %in% drop_filters), 2),
Enrolls = n(),
Drops = sum(GRADE %in% drop_filters)) %>%
arrange(desc(`Drop Rate`))
}
})
output$grades_hist <- renderPlotly({
if (input$groupdatahist == TRUE) {
ggplotly(
all_data %>%
filter(Option == "Premium",
RegDate > "2015-07-01" & RegDate < "2015-11-01",
Teacher == input$teacher,
!(GRADE %in% drop_filters)) %>%
ggplot(aes(as.numeric(GRADE))) +
geom_histogram(binwidth = input$slider, fill = "pink", color = "black") +
ggtitle("Grade Distribution") +
labs(x = "Grade") +
theme_minimal()
)
} else {
all_data %>%
filter(Option == "Premium",
RegDate > "2015-07-01" & RegDate < "2015-11-01",
Teacher == input$teacher,
!(GRADE %in% drop_filters)) %>%
ggplot(aes(as.numeric(GRADE))) +
geom_histogram(binwidth = input$slider, fill = "pink", color = "black") +
ggtitle("Grade Distribution") +
facet_grid(. ~ Course) +
labs(x = "Grade") +
theme_minimal()
}
})
output$enhanced <- renderTable({
eval_text_data %>%
filter(Teacher == input$teacher) %>%
select(2) %>%
filter(!is.na(.[,1]))
})
output$change <- renderTable({
eval_text_data %>%
filter(Teacher == input$teacher) %>%
select(3) %>%
filter(!is.na(.[,1]))
})
output$dotplot <- renderPlot({
eval_response_data %>%
mutate(Response = factor(Response,
levels = c("Strongly Disagree", "Somewhat Disagree", "Neither Agree nor Disagree", "Somewhat Agree", "Strongly Agree"))) %>%
group_by(Teacher) %>%
summarize(teacher_rating = sum(mean(as.numeric(Response)))) %>%
mutate(fillcolor = ifelse(Teacher == input$teacher, "fill", "nofill")) %>%
arrange(desc(teacher_rating)) %>%
ggplot(aes(teacher_rating, fill = fillcolor)) +
geom_dotplot(binwidth = 0.15, aes(size = 1)) +
scale_y_continuous(NULL, breaks = NULL) +
labs(x = "Teacher Rating") +
scale_fill_manual(values = c("lightgreen", "black")) +
theme_minimal() +
theme(legend.position="none")
})
}
shinyApp(ui = ui, server = server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment