From 60c14c1b69921e66b1f88c7b22ad8aeda16a4967 Mon Sep 17 00:00:00 2001 From: Patrick Callahan Date: Mon, 8 Jul 2024 21:15:44 +0200 Subject: [PATCH] Styler --- .Rprofile | 2 -- R/app_server.R | 23 ++++++++++++----------- R/app_ui.R | 2 +- R/caption_builder.R | 3 --- R/mod_app_description.R | 7 +++---- R/mod_final_grade_display.R | 7 +++---- R/mod_info_textbox.R | 9 ++++----- tests/testthat/test-caption_builder.R | 7 ++++--- vignettes/gradecast.Rmd | 16 +++++++++------- 9 files changed, 36 insertions(+), 40 deletions(-) diff --git a/.Rprofile b/.Rprofile index ab439cf..6fd87e6 100644 --- a/.Rprofile +++ b/.Rprofile @@ -1,11 +1,9 @@ source("renv/activate.R") .First <- function() { - options( shiny.autoreload = TRUE ) shiny::reactiveConsole(TRUE) - } diff --git a/R/app_server.R b/R/app_server.R index b2056e9..22e6bed 100644 --- a/R/app_server.R +++ b/R/app_server.R @@ -23,17 +23,18 @@ app_server <- function(input, output, session) { ) mod_info_textbox_server("info_textbox_1", - min_passing_grade = min_passing_grade_1, - max_passing_grade = max_passing_grade_1, - caption_width = 200, - run_button = run_button) + min_passing_grade = min_passing_grade_1, + max_passing_grade = max_passing_grade_1, + caption_width = 200, + run_button = run_button + ) mod_final_grade_display_server("final_grade_display_1", - completed_ects = completed_ects_1, - current_grade = current_grade_1, - remaining_ects = remaining_ects_1, - max_passing_grade = max_passing_grade_1, - min_passing_grade = min_passing_grade_1, - run_button = run_button - ) + completed_ects = completed_ects_1, + current_grade = current_grade_1, + remaining_ects = remaining_ects_1, + max_passing_grade = max_passing_grade_1, + min_passing_grade = min_passing_grade_1, + run_button = run_button + ) } diff --git a/R/app_ui.R b/R/app_ui.R index 1af08b7..a8bab58 100644 --- a/R/app_ui.R +++ b/R/app_ui.R @@ -40,7 +40,7 @@ app_ui <- function(request) { min_height = 175, bslib::card_header("Plot Info"), mod_info_textbox_ui("info_textbox_1") - ) + ) ) ) } diff --git a/R/caption_builder.R b/R/caption_builder.R index 34b03cd..2f3603b 100644 --- a/R/caption_builder.R +++ b/R/caption_builder.R @@ -1,5 +1,3 @@ - - #' Caption builder #' #' Builds the text caption for the grade range plot. The caption can be optionally turned off on the ggplot2 object which is useful when the text is not needed or rendered well on the image file. Instead, the Shiny app creates a separate text box for the caption. @@ -17,7 +15,6 @@ #' caption_builder(min_passing_grade = 5, max_passing_grade = 1) #' caption_builder <- function(min_passing_grade, max_passing_grade, caption_width = 150, show_caption = TRUE) { - assertthat::assert_that( is.numeric(min_passing_grade), is.numeric(max_passing_grade), diff --git a/R/mod_app_description.R b/R/mod_app_description.R index 2e3dd18..134241a 100644 --- a/R/mod_app_description.R +++ b/R/mod_app_description.R @@ -7,7 +7,7 @@ #' @noRd #' #' @importFrom shiny NS tagList -mod_app_description_ui <- function(id){ +mod_app_description_ui <- function(id) { ns <- NS(id) tagList( "Have you ever looked at your current Notendurchschnitt (Grade Point Average or GPA), and wondered how much you can improve your grades by the of your program? (Alternatively: do you want to estimate how much you can slack off and still pass your program?) Then this app is for you! Just input how much of your program you've already completed (Completed ECTS), your current grades (Current Grades) and how much of your program remains (Remaining ECTS).", @@ -18,10 +18,9 @@ mod_app_description_ui <- function(id){ #' app_description Server Functions #' #' @noRd -mod_app_description_server <- function(id){ - moduleServer( id, function(input, output, session){ +mod_app_description_server <- function(id) { + moduleServer(id, function(input, output, session) { ns <- session$ns - }) } diff --git a/R/mod_final_grade_display.R b/R/mod_final_grade_display.R index 790ac9a..98d1eb5 100644 --- a/R/mod_final_grade_display.R +++ b/R/mod_final_grade_display.R @@ -7,7 +7,7 @@ #' @noRd #' #' @importFrom shiny NS tagList -mod_final_grade_display_ui <- function(id){ +mod_final_grade_display_ui <- function(id) { ns <- NS(id) tagList( bslib::layout_columns( @@ -22,8 +22,8 @@ mod_final_grade_display_ui <- function(id){ #' #' @noRd mod_final_grade_display_server <- function(id, completed_ects, current_grade, remaining_ects, - max_passing_grade, min_passing_grade, run_button){ - moduleServer( id, function(input, output, session){ + max_passing_grade, min_passing_grade, run_button) { + moduleServer(id, function(input, output, session) { ns <- session$ns parameters <- reactive({ @@ -62,7 +62,6 @@ mod_final_grade_display_server <- function(id, completed_ects, current_grade, re showcase = bsicons::bs_icon("emoji-frown") ) }) - }) } diff --git a/R/mod_info_textbox.R b/R/mod_info_textbox.R index e0ef1e3..0631b24 100644 --- a/R/mod_info_textbox.R +++ b/R/mod_info_textbox.R @@ -7,7 +7,7 @@ #' @noRd #' #' @importFrom shiny NS tagList -mod_info_textbox_ui <- function(id){ +mod_info_textbox_ui <- function(id) { ns <- NS(id) tagList( textOutput(ns("info_textbox")) @@ -18,8 +18,8 @@ mod_info_textbox_ui <- function(id){ #' #' @noRd mod_info_textbox_server <- function(id, min_passing_grade, max_passing_grade, - caption_width = 150, run_button){ - moduleServer( id, function(input, output, session){ + caption_width = 150, run_button) { + moduleServer(id, function(input, output, session) { ns <- session$ns text <- eventReactive(run_button(), ignoreNULL = FALSE, { @@ -28,13 +28,12 @@ mod_info_textbox_server <- function(id, min_passing_grade, max_passing_grade, max_passing_grade = max_passing_grade(), caption_width = caption_width, show_caption = TRUE - ) + ) }) output$info_textbox <- renderText({ text() }) - }) } diff --git a/tests/testthat/test-caption_builder.R b/tests/testthat/test-caption_builder.R index c3fdfa9..30e00ad 100644 --- a/tests/testthat/test-caption_builder.R +++ b/tests/testthat/test-caption_builder.R @@ -1,4 +1,3 @@ - test_that("check caption_builder null", { expect_equal( caption_builder( @@ -7,7 +6,8 @@ test_that("check caption_builder null", { caption_width = 100, show_caption = FALSE ), - NULL) + NULL + ) }) test_that("check caption_builder not null", { @@ -19,7 +19,8 @@ test_that("check caption_builder not null", { show_caption = TRUE ), stringr::str_wrap("The shaded region represents the range of all possible grade averages that can be achieved based on three factors: 1) the current grade average or GPA, 2) the number of ECTS credits already completed, and 3) the amount of remaining ECTS.\n\nThe red line indicates the worst possible scenario i.e. obtaining 5s in all classes while the green line indicates the best possible scenario i.e. obtaining 1s in all classes. The blue dashed line represents the highest passing grade.", - width = 100) + width = 100 + ) ) }) diff --git a/vignettes/gradecast.Rmd b/vignettes/gradecast.Rmd index f0b76f4..6180218 100644 --- a/vignettes/gradecast.Rmd +++ b/vignettes/gradecast.Rmd @@ -44,7 +44,8 @@ grade <- 1.5 remaining <- 90 calculate_grade_range(completed, grade, remaining, - max_passing_grade = 1, min_passing_grade = 5) + max_passing_grade = 1, min_passing_grade = 5 +) ``` ### Plotting the grade range @@ -65,9 +66,9 @@ Using the same scenario from the previous example, we can use the `plot_grade_ra ```{r, results = "asis", fig.width = 7, fig.height = 5, fig.align = "center"} plot_grade_range(completed, grade, remaining, - max_passing_grade = 1, min_passing_grade = 5, - caption_width = 100) - + max_passing_grade = 1, min_passing_grade = 5, + caption_width = 100 +) ``` Note: this function actually wraps the `calculate_grade_range()` function and creates a ggplot2 object based on the results (hence the reason for having many of the same arguments). The ggplot2 object can be further customized using the standard ggplot2 syntax. @@ -86,9 +87,10 @@ The function returns a character string that contains the text for the caption. As an example, let's build the caption for the grade range plot with the worst possible grade of 5 and the best possible grade of 1. ```{r} -caption_builder(min_passing_grade = 5, max_passing_grade = 1, - caption_width = 150, show_caption = TRUE) - +caption_builder( + min_passing_grade = 5, max_passing_grade = 1, + caption_width = 150, show_caption = TRUE +) ```