Skip to content

Commit

Permalink
Styler
Browse files Browse the repository at this point in the history
  • Loading branch information
NeuroShepherd committed Jul 8, 2024
1 parent e4d292b commit 60c14c1
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 40 deletions.
2 changes: 0 additions & 2 deletions .Rprofile
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
source("renv/activate.R")

.First <- function() {

options(
shiny.autoreload = TRUE
)

shiny::reactiveConsole(TRUE)

}
23 changes: 12 additions & 11 deletions R/app_server.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
2 changes: 1 addition & 1 deletion R/app_ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ app_ui <- function(request) {
min_height = 175,
bslib::card_header("Plot Info"),
mod_info_textbox_ui("info_textbox_1")
)
)
)
)
}
Expand Down
3 changes: 0 additions & 3 deletions R/caption_builder.R
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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),
Expand Down
7 changes: 3 additions & 4 deletions R/mod_app_description.R
Original file line number Diff line number Diff line change
Expand Up @@ -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).",
Expand All @@ -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

})
}

Expand Down
7 changes: 3 additions & 4 deletions R/mod_final_grade_display.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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({
Expand Down Expand Up @@ -62,7 +62,6 @@ mod_final_grade_display_server <- function(id, completed_ects, current_grade, re
showcase = bsicons::bs_icon("emoji-frown")
)
})

})
}

Expand Down
9 changes: 4 additions & 5 deletions R/mod_info_textbox.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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, {
Expand All @@ -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()
})

})
}

Expand Down
7 changes: 4 additions & 3 deletions tests/testthat/test-caption_builder.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

test_that("check caption_builder null", {
expect_equal(
caption_builder(
Expand All @@ -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", {
Expand All @@ -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
)
)
})

Expand Down
16 changes: 9 additions & 7 deletions vignettes/gradecast.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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
)
```


Expand Down

0 comments on commit 60c14c1

Please sign in to comment.