Skip to content

Commit

Permalink
solved UI pb when changing input file
Browse files Browse the repository at this point in the history
  • Loading branch information
gaelso committed Nov 14, 2024
1 parent b27ecdc commit cbe98a9
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 33 deletions.
6 changes: 4 additions & 2 deletions R/mod_tool_UI.R
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ mod_tool_UI <- function(id, i18n){
## ++ Value boxes ------------------------------------------------------------
vb_time <- value_box(
title = "Time periods",
value = textOutput(ns("vb_nb_time")),
value = htmlOutput(ns("vb_nb_time")),
showcase = bsicons::bs_icon("calendar3", size = "40px"),
theme = "primary",
textOutput(ns("vb_nb_ref")),
Expand Down Expand Up @@ -190,7 +190,9 @@ mod_tool_UI <- function(id, i18n){

card_lumatrix <- card(
h5(i18n$t("Land use change matrix")),
gt::gt_output(ns("lumatrix"))
uiOutput(outputId = ns("check_slider_UI")),
verbatimTextOutput(ns("check_lumatrix"))
#gt::gt_output(ns("check_lumatrix"))
)

## combine cards
Expand Down
79 changes: 48 additions & 31 deletions R/mod_tool_server.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,27 @@ mod_tool_server <- function(id, rv) {
shinyjs::hide("check_vbs")
shinyjs::hide("check_cards")

shinyWidgets::updateProgressBar(session = session, id = "prog_allchecks", value = 0, status = "primary")
## Reset indicator that all checks are done
rv$checks$all_done <- NULL

## ++ Read data ----------------------------------------------------------
shinyWidgets::updateProgressBar(
title = "Loading data...",
session = session, id = "prog_allchecks", value = 0, status = "primary"
)

rv$inputs$usr <- readxl::read_xlsx(rv$inputs$xlsx_path, sheet = "user_inputs", na = "NA")
rv$inputs$time <- readxl::read_xlsx(rv$inputs$xlsx_path, sheet = "time_periods", na = "NA")
rv$inputs$ad <- readxl::read_xlsx(rv$inputs$xlsx_path, sheet = "AD_lu_transitions", na = "NA")
rv$inputs$cs <- readxl::read_xlsx(rv$inputs$xlsx_path, sheet = "c_stocks", na = "NA")

Sys.sleep(0.1)

## ++ Run checks ---------------------------------------------------------
shinyWidgets::updateProgressBar(
title = "Data loaded...",
title = "Checking input file...",
session = session, id = "prog_allchecks", value = 25
)

## ++ Run checks ---------------------------------------------------------
)

## Use fct_check_data2()
rv$checks$check_data <- fct_check_data2(
Expand All @@ -96,52 +101,50 @@ mod_tool_server <- function(id, rv) {

Sys.sleep(0.1)

## ++ Calculations -------------------------------------------------------
shinyWidgets::updateProgressBar(
title = "Checks completed...",
title = "Running Calculations...",
session = session, id = "prog_allchecks", value = 50
)

## ++ Calculations -------------------------------------------------------
Sys.sleep(0.1)

rv$checks$sim_trans_ar <- fct_combine_mcs_E(.ad = rv$inputs$ad, .cs = rv$inputs$cs, .usr = rv$inputs$usr)
rv$checks$sim_FREL_ar <- fct_combine_mcs_P(
.data = sim_trans,
.time = rv$inputs$time,
.period_type = "REF",
.ad_annual = rv$inputs$usr$ad_annual
)

shinyWidgets::updateProgressBar(
title = "Calculations done...",
session = session, id = "prog_allchecks", value = 75
)
# rv$checks$sim_trans_ar <- fct_combine_mcs_E(.ad = rv$inputs$ad, .cs = rv$inputs$cs, .usr = rv$inputs$usr)
# rv$checks$sim_FREL_ar <- fct_combine_mcs_P(
# .data = rv$checks$sim_trans_ar,
# .time = rv$inputs$time,
# .period_type = "reference",
# .ad_annual = rv$inputs$usr$ad_annual
# )

Sys.sleep(0.5)

## ++ Outputs ------------------------------------------------------------
## outputs are calculated once new data is uploaded so they are performed here
## instead of the render*({}) functions
shinyWidgets::updateProgressBar(
title = "Preparing outputs...",
session = session, id = "prog_allchecks", value = 50
)

Sys.sleep(0.5)

## ++ Finalize -----------------------------------------------------------
shinyWidgets::updateProgressBar(
title = "All steps completed...",
session = session, id = "prog_allchecks", value = 100, status = "success"
)
)

## ++ Finalize -----------------------------------------------------------
rv$checks$all_done <- TRUE


})

## + Outputs ===============================================================

## ++ value box content ----------------------------------------------------
## +++ Time related ----
output$vb_nb_time <- renderText({
output$vb_nb_time <- renderUI({
req(rv$checks$check_data$all_ok)
if (rv$checks$check_data$all_ok) {
paste0(nrow(rv$inputs$time), " periods")
HTML(paste0(nrow(rv$inputs$time), "&nbsp;periods"))
}
})

Expand All @@ -166,6 +169,7 @@ mod_tool_server <- function(id, rv) {
## +++ CS related ----

## ++ Cards content --------------------------------------------------------
## +++ Table of checks ----
output$check_msg <- gt::render_gt({
req(rv$checks$all_done)

Expand Down Expand Up @@ -204,26 +208,39 @@ mod_tool_server <- function(id, rv) {

output$check_arithmetic_gg <- renderPlot({ })

output$check_lumatrix <- gt::render_gt({ })
## +++ LU change matrix ----
output$check_slider_UI <- renderUI({
selectInput(
inputId = ns("check_slider_period"),
label = "Select a time period",
choices = rv$inputs$time$period_no
)
})

#output$check_lumatrix <- gt::render_gt({ })

# observe({
# req(input$check_slider_period)
# rv$checks$check_slider_period <- input$check_slider_period
# })

output$check_lumatrix <- renderText({ input$check_slider_period })

## + UI changes ============================================================

## Update show / hide panels
observe({
req(rv$checks$all_done)
shinyjs::show("check_show")
})

if (rv$checks$all_done) shinyjs::show("check_show") else shinyjs::hide("check_show")

observeEvent(input$btn_show_checks, {
})

observeEvent(input$btn_show_checks, {
shinyjs::hide("check_progress")
shinyjs::hide("check_show")
shinyjs::show("check_vbs")
shinyjs::show("check_cards")

})

# submod_check_server("tab_check", rv = rv)
Expand Down
6 changes: 6 additions & 0 deletions inst/assets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,9 @@
--bs-border-radius-xxl: 2rem;
--bs-border-radius-2xl: var(--bs-border-radius-xxl);
}

/* Rm container-name to avoid showcase moving to top in value box */
.bslib-value-box {
container-name: none !important;
}

Binary file modified inst/extdata/example1.xlsx
Binary file not shown.
Binary file added inst/extdata/test-example1.xlsx
Binary file not shown.

0 comments on commit cbe98a9

Please sign in to comment.