Skip to content

Commit

Permalink
Make plot generation event reactive
Browse files Browse the repository at this point in the history
  • Loading branch information
NeuroShepherd committed Jul 8, 2024
1 parent e0e4bec commit 497bc29
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 15 deletions.
4 changes: 3 additions & 1 deletion R/app_server.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ app_server <- function(input, output, session) {
remaining_ects_1 <- mod_remaining_ects_server("remaining_ects_1")
max_passing_grade_1 <- mod_max_passing_grade_server("max_passing_grade_1")
min_passing_grade_1 <- mod_min_passing_grade_server("min_passing_grade_1")
run_button <- mod_run_button_server("run_button_1")

mod_plot_grade_server("plot_grade_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)
min_passing_grade = min_passing_grade_1,
run_button = run_button)



Expand Down
3 changes: 2 additions & 1 deletion R/app_ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ app_ui <- function(request) {
mod_current_grade_ui("current_grade_1"),
mod_remaining_ects_ui("remaining_ects_1"),
mod_max_passing_grade_ui("max_passing_grade_1"),
mod_min_passing_grade_ui("min_passing_grade_1")
mod_min_passing_grade_ui("min_passing_grade_1"),
mod_run_button_ui("run_button_1")
),
bslib::card(
bslib::card_header("Hello"),
Expand Down
27 changes: 14 additions & 13 deletions R/mod_plot_grade.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ mod_plot_grade_ui <- function(id){
#'
#' @noRd
mod_plot_grade_server <- function(id, completed_ects, current_grade, remaining_ects,
max_passing_grade, min_passing_grade) {
max_passing_grade, min_passing_grade, run_button) {
moduleServer( id, function(input, output, session){
ns <- session$ns

browser()
# browser()

parameters <- reactive({
list(
Expand All @@ -34,21 +34,22 @@ mod_plot_grade_server <- function(id, completed_ects, current_grade, remaining_e
)
})

output$grade_plot <- shiny::renderPlot({

plot_grade_range(
completed_ects = parameters()$completed_ects,
current_grade = parameters()$current_grade,
remaining_ects = parameters()$remaining_ects,
max_passing_grade = parameters()$max_passing_grade,
min_passing_grade = parameters()$min_passing_grade
)

plot_obj <- eventReactive(run_button(), ignoreNULL = FALSE, {
plot_grade_range(
completed_ects = parameters()$completed_ects,
current_grade = parameters()$current_grade,
remaining_ects = parameters()$remaining_ects,
max_passing_grade = parameters()$max_passing_grade,
min_passing_grade = parameters()$min_passing_grade
)
})

output$grade_plot <- renderPlot({
plot_obj()
})


})
})
}

## To be copied in the UI
Expand Down
33 changes: 33 additions & 0 deletions R/mod_run_button.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#' run_button UI Function
#'
#' @description A shiny Module.
#'
#' @param id,input,output,session Internal parameters for {shiny}.
#'
#' @noRd
#'
#' @importFrom shiny NS tagList
mod_run_button_ui <- function(id){
ns <- NS(id)
tagList(
actionButton(ns("run_button"), "Run")
)
}

#' run_button Server Functions
#'
#' @noRd
mod_run_button_server <- function(id){
moduleServer( id, function(input, output, session){
ns <- session$ns

return(reactive(input$run_button))

})
}

## To be copied in the UI
# mod_run_button_ui("run_button_1")

## To be copied in the server
# mod_run_button_server("run_button_1")

0 comments on commit 497bc29

Please sign in to comment.