Skip to content

Commit

Permalink
tidy code
Browse files Browse the repository at this point in the history
  • Loading branch information
rmbielby committed Nov 16, 2023
1 parent f409935 commit db0b3f3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 22 deletions.
17 changes: 15 additions & 2 deletions .hooks/pre-commit.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
cat("Running commit hooks...",fill=TRUE)
shhh <- suppressPackageStartupMessages # It's a library, so shhh!
shhh(library(dplyr))
shhh(library(dfeshiny))
shhh(library(xfun))


Expand All @@ -12,7 +13,7 @@ log_files <- read.csv(datalog, stringsAsFactors = FALSE)
ign_files <- read.csv(".gitignore", header = FALSE, stringsAsFactors = FALSE)
colnames(ign_files)[1] <- "filename"

cat("Contents of the .gitignore file:",fill=TRUE)
cat("Contents of the .gitignore file:")
print(ign_files)

# Run a pass through the .gitignore files and look for any issues
Expand Down Expand Up @@ -57,9 +58,10 @@ for (file in current_files$files) {
}

if(grepl('G-Z967JJVQQX', htmltools::includeHTML(("google-analytics.html"))) &
!(toupper(Sys.getenv("USERNAME")) %in% c("CFOSTER4", "CRACE", "LSELBY","RBIELBY"))){
!(toupper(Sys.getenv("USERNAME")) %in% c("CFOSTER4", "CRACE", "LSELBY","RBIELBY", "JMACHIN"))){
cat("Cleaning out the template's Google Analytics tag.",fill=TRUE)
gsub_file("google-analytics.html", pattern = "G-Z967JJVQQX", replacement = "G-XXXXXXXXXX")
gsub_file("ui.R", pattern = "Z967JJVQQX", replacement = "XXXXXXXXXX")
system2(command = "git", args=c("add","google-analytics.html"))
}

Expand All @@ -68,4 +70,15 @@ if (error_flag) {
quit(save = "no", status = 1, runLast = FALSE)
}

tidy_output <- tidy_code()
if(any(tidy_output)){
error_flag <- TRUE
}

if (error_flag) {
cat("Warning: Code did not appear to have been tidied.\nI've run tidy code for you,
please check your files and the dashboard still works and then re-stage and try committing again.")
quit(save = "no", status = 1, runLast = FALSE)
}

# End of hooks
20 changes: 8 additions & 12 deletions R/plotting.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,10 @@ createTimeSeriesHeadline <- function(dfAps, allAps) {
fig <- ggplot(
fig, aes(x = Year, y = APS, group = Qualification, color = Qualification)
) +

geom_line(stat = "identity", linewidth = 1) +
scale_color_manual(values = c("#12436D", "#28A197", "#801650")) +
# scale_x_log10(breaks = seq(2016, 2023, 2)) +
labs(x = "", y = "", color = "") +

coord_cartesian(ylim = c(0, 60)) +
scale_x_continuous(breaks = seq(2016, 2023, 1)) +
theme_classic() +
Expand All @@ -66,7 +64,7 @@ createTimeSeriesHeadline <- function(dfAps, allAps) {
) +
expand_limits(x = 2016, y = 0) +
ggtitle(paste0("\n Average point score: ", allAps))

ggplotly(fig, tooltip = c("x", "y", "colour")) %>%
config(
modeBarButtonsToRemove = c(
Expand All @@ -81,8 +79,6 @@ createTimeSeriesHeadline <- function(dfAps, allAps) {
legend = list(orientation = "h", x = .1, y = .2), #-.3),
hovermode = "x"
)


}


Expand All @@ -93,11 +89,11 @@ createTimeSeriesHeadline <- function(dfAps, allAps) {

createApsTimeSeries <- function(dfAps, instGroup, instType, allGender) {
validate(need(dfAps$school_type, message = "To view charts select type of students and up to 4 institution types from the drop-down menus at the top page"))
fig2<-dfAps%>%

fig2 <- dfAps %>%
filter(year >= 2016)


fig1 <- ggplot(dfAps, aes(x = year_2013_2015, y = aps_2013_2015, color = school_type)) +
geom_line(stat = "identity", linewidth = 1.5) +
geom_curve(aes(x = 2015.5, y = 50, xend = 2015, yend = 45),
Expand Down Expand Up @@ -337,12 +333,12 @@ createTimeSeriesResult <- function(dfSubjectA, subAll, resAll, subName) {
validate(need(dfSubjectA$subject_name, message = "To view chart select type of students, select up to 4 subjects and start year from the drop-down menus at the top of the page. Finally select cumulative grade"))



fig <- dfSubjectA %>%
rename(Year = "year", Subject = "subject_name")


fig <- ggplot(fig, aes_string(x="Year", y=resAll, color="Subject")) +
fig <- ggplot(fig, aes_string(x = "Year", y = resAll, color = "Subject")) +
geom_line(stat = "identity", linewidth = 1, show.legend = F) +
# geom_point(stat= "identity", size=1.5, show.legend=F)+
scale_x_log10(breaks = seq(1996, 2023, 2)) +
Expand Down Expand Up @@ -443,7 +439,7 @@ createTimeSeriesResultFm <- function(dfSubjectG, subByFm, resByFm) {
fig <- dfSubjectG %>%
rename(Year = "year", Subject = "subject_name", Gender = "characteristic_gender")

fig <- ggplot(fig, aes_string("Year", y=resByFm, color = "Gender")) +
fig <- ggplot(fig, aes_string("Year", y = resByFm, color = "Gender")) +
geom_line(stat = "identity", linewidth = 1) +
# geom_point(size=1.5)+
scale_color_manual(values = c("#3D3D3D", "#F46A25", "#12436D")) +
Expand Down
7 changes: 4 additions & 3 deletions global.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# Library calls ---------------------------------------------------------------------------------
shhh <- suppressPackageStartupMessages # It's a library, so shhh!
shhh(library(shiny))
#shhh(library(shinya11y))
# shhh(library(shinya11y))
shhh(library(shinyjs))
shhh(library(tools))
shhh(library(testthat))
Expand Down Expand Up @@ -177,9 +177,10 @@ dfAlevelAps <- data %>%
) %>%
select(
time_period, year, school_type, school_type_group, number_of_students, aps_2016_2023, aps_2013_2015, aps_grade_2016_2023, aps_grade_2013_2015,
characteristic_gender, time_period, year_2016_2023, year_2013_2015, version) %>%
characteristic_gender, time_period, year_2016_2023, year_2013_2015, version
) %>%
mutate(
year_2016_2023=year,
year_2016_2023 = year,
aps_grade_2016_2023 = as.factor(aps_grade_2016_2023),
aps_grade_2013_2015 = as.factor(aps_grade_2013_2015),
aps_2016_2023 = round(as.numeric(aps_2016_2023), 2),
Expand Down
10 changes: 5 additions & 5 deletions server.R
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ server <- function(input, output, session) {
filter(year == max(year), cert_type == "A level", school_type == input$headlineAps))$aps_grade

valueBox(
value = grade, subtitle = paste0("Average A level result equivalent to ", latest, " points: " , input$headlineAps), # width = 12,
value = grade, subtitle = paste0("Average A level result equivalent to ", latest, " points: ", input$headlineAps), # width = 12,
color = "blue"
)
})
Expand All @@ -198,7 +198,7 @@ server <- function(input, output, session) {
grade <- (reactiveHeadline() %>%
filter(year == max(year), cert_type == "Applied general", school_type == input$headlineAps))$aps_grade
valueBox(
value = grade, subtitle = paste0("Average applied general result equivalent to ", latest, " points: " , input$headlineAps),
value = grade, subtitle = paste0("Average applied general result equivalent to ", latest, " points: ", input$headlineAps),
color = "blue"
)
})
Expand All @@ -212,7 +212,7 @@ server <- function(input, output, session) {
grade <- (reactiveHeadline() %>%
filter(year == max(year), cert_type == "Tech level", school_type == input$headlineAps))$aps_grade
valueBox(
value = grade, subtitle = paste0("Average tech level result equivalent to ", latest, " points: " , input$headlineAps),
value = grade, subtitle = paste0("Average tech level result equivalent to ", latest, " points: ", input$headlineAps),
color = "blue"
)
})
Expand Down Expand Up @@ -433,9 +433,9 @@ server <- function(input, output, session) {
val <- paste(input$headlineAps, collapse = ",")
# val1<-paste(input$allGender, collapse=", ")
paste("The boxes display the latest provisional average results in 2022/23 for A level, applied general and tech level. In 2018, there was a large drop in the number of applied general
and tech level students. This was due to the change in the list of tech level and applied general qualifications eligible for reporting in the performance tables.
and tech level students. This was due to the change in the list of tech level and applied general qualifications eligible for reporting in the performance tables.
Point scores for 2020 and 2021 are based on Centre assessment grade and Teacher assessed grade respectively.
The chart shows the APS from 2015/16 to 2022/23 for ", val, " in England. To view results, click on the drop-down box and select one institution type.
")
})
Expand Down

0 comments on commit db0b3f3

Please sign in to comment.