Skip to content

Commit

Permalink
v0.15.0 - experiment with a second SDG mode that allows changes in in…
Browse files Browse the repository at this point in the history
…dividual causes of

death;
  • Loading branch information
mpascariu committed Jan 16, 2024
1 parent c4ed4a1 commit 8bda3c1
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 123 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: lemur
Title: Life expectancy monitor upscaled in R
Version: 0.14.4
Version: 0.15.0
Authors@R: c(
person("Marius D.", "Pascariu", role = c("aut", "cre", "cph"), email = "rpascariu@outlook.com", comment = c(ORCID = "0000-0002-2568-6489")),
person("Jose Manuel", "Aburto", role = "aut", comment = c(ORCID = "0000-0002-2926-6879")),
Expand Down Expand Up @@ -42,7 +42,7 @@ Imports:
RPostgres (>= 1.4.5)
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.2.3
RoxygenNote: 7.3.0
Suggests:
testthat (>= 3.0.0)
Depends:
Expand Down
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
version 0.15.0
- experiment with a second SDG mode that allows changes in individual causes of
death;

version 0.14.2
- Update docker container;

Expand Down
8 changes: 4 additions & 4 deletions R/app_captions.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -------------------------------------------------------------- #
# Author: Marius D. PASCARIU
# Last Update: Wed Nov 8 13:50:34 2023
# Last Update: Tue Jan 16 18:21:29 2024
# -------------------------------------------------------------- #

# ALL THE INFORMATIVE CAPTIONS FOR FIGURES AND TABLES ARE CODED HERE
Expand Down Expand Up @@ -56,7 +56,7 @@ generate_table_captions <- function(mode,
"SDG accomplishment levels applied to one or more risks factors ",
"as specified in the dashboard.")

if (mode %in% c("mode_cod", "mode_sdg")) {
if (mode %in% c("mode_cod", "mode_sdg", "mode_sdg2")) {
lt_initial <- paste0(
"TABLE 1 -- Life table for ", part1, ". ", part2,
" TABLE 2 below includes such alterations."
Expand All @@ -79,7 +79,7 @@ generate_table_captions <- function(mode,
)
}

if (mode == "mode_sdg") {
if (mode %in% c("mode_sdg", "mode_sdg2")) {

lt_final <- paste0(
"TABLE 2 -- Hypothetical life table for ", part1, ". ", part4
Expand Down Expand Up @@ -194,7 +194,7 @@ generate_fig2_captions <- function(mode,
}

# Part 3 - Life expectancy before and after
if (mode %in% c("mode_cod", "mode_sdg")) {
if (mode %in% c("mode_cod", "mode_sdg", "mode_sdg2")) {
prefix1 <- "Before: "
prefix2 <- "After the changes: "
}
Expand Down
2 changes: 1 addition & 1 deletion R/app_process_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Last Update: Tue Dec 19 22:08:15 2023
# -------------------------------------------------------------- #

# somebody should merge these functions in 1?
# somebody should merge these functions into 1 function?

# ----------------------------------------------------------------------------
# PROCESS DATA
Expand Down
73 changes: 68 additions & 5 deletions R/app_server.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -------------------------------------------------------------- #
# Author: Marius D. PASCARIU
# Last Update: Tue Dec 5 22:23:04 2023
# Last Update: Tue Jan 16 18:31:54 2024
# -------------------------------------------------------------- #

#' The application server-side
Expand All @@ -22,7 +22,7 @@ app_server <- function(input, output, session) {

# 1) cod data ---
data_cod <- reactive({
if (input$mode != "mode_sdg") {
if (input$mode %in% c("mode_cod", "mode_sex", "mode_cntr") ) {

dataSource <- if (serverMode()) "cod" else lemur::data_gbd2019_cod

Expand All @@ -44,7 +44,7 @@ app_server <- function(input, output, session) {

# 2) sdg data ---
data_sdg <- reactive({
if (input$mode == "mode_sdg") {
if (input$mode %in% c("mode_sdg", "mode_sdg2")) {

dataSource <- if (serverMode()) "sdg" else lemur::data_gbd2019_sdg

Expand Down Expand Up @@ -146,7 +146,39 @@ app_server <- function(input, output, session) {
}
}

} else if (input$mode == 'mode_sdg2') {

M <- build_reduction_matrix(
data = data_sdg(),
select_cod = as.character(unique(data_sdg()$cause_name)),
select_x = 0:110,
cod_change = 0
)

M[ , "Cardiovascular Diseases"] <- input$sdg2_1
M[ , "Chronic Respiratory Diseases"] <- input$sdg2_2
M[ , "Diabetes"] <- input$sdg2_3
M[ , "Enteric Infections"] <- input$sdg2_4
M[ , "Exposure to Forces of Nature"] <- input$sdg2_5
M[ , "HIV/ AIDS / STD"] <- input$sdg2_6
M[ , "Injuries (excl. Poisonings)"] <- input$sdg2_7
M[ , "Interpersonal Violence"] <- input$sdg2_8
M[ , "Kidney Disease"] <- input$sdg2_9
M[ , "Malaria"] <- input$sdg2_10
if (input$sex != 'male') M[ , "Maternal disorders"] <- input$sdg2_11
M[ , "Neglected Tropical Diseases (excl. Malaria)"] <- input$sdg2_12
M[ , "Neonatal disorders"] <- input$sdg2_13
M[ , "Neoplasms"] <- input$sdg2_14
M[ , "Other Communicable"] <- input$sdg2_15
M[ , "Other Non-Communicable"] <- input$sdg2_16
M[ , "Poisonings"] <- input$sdg2_17
M[ , "Respiratory Infections (excl. Tuberculosis)"] <- input$sdg2_18
M[ , "Self-Harm"] <- input$sdg2_19
M[ , "Transport Injuries"] <- input$sdg2_20
M[ , "Tuberculosis"] <- input$sdg2_21

} else {

M <- build_reduction_matrix(
data = data_cod(),
select_cod = input$cod_target,
Expand Down Expand Up @@ -199,7 +231,16 @@ app_server <- function(input, output, session) {
region2 = input$region2,
sex = input$sex,
cod_change = data_cod_change()
)
),

mode_sdg2 = prepare_data_mode_cod(
cod = data_sdg(),
lt = data_lt(),
region1 = input$region1,
region2 = input$region2,
sex = input$sex,
cod_change = data_cod_change()
)
)
})

Expand Down Expand Up @@ -419,7 +460,7 @@ app_server <- function(input, output, session) {
type = "barplot") +
facet_wrap("sex")

} else if (input$mode == "mode_sdg") {
} else if (input$mode %in% c("mode_sdg", "mode_sdg2")) {
p <- plot_cod(
cod = data_fig()$cod_final,
perc = input$perc,
Expand Down Expand Up @@ -531,6 +572,28 @@ app_server <- function(input, output, session) {
updateSliderInput(session, 'sdg_5', value = 0)
updateSliderInput(session, 'sdg_6', value = 0)
updateSliderInput(session, 'sdg_7', value = 0)

updateSliderInput(session, 'sdg2_1', value = 0)
updateSliderInput(session, 'sdg2_2', value = 0)
updateSliderInput(session, 'sdg2_3', value = 0)
updateSliderInput(session, 'sdg2_4', value = 0)
updateSliderInput(session, 'sdg2_5', value = 0)
updateSliderInput(session, 'sdg2_6', value = 0)
updateSliderInput(session, 'sdg2_7', value = 0)
updateSliderInput(session, 'sdg2_8', value = 0)
updateSliderInput(session, 'sdg2_9', value = 0)
updateSliderInput(session, 'sdg2_10', value = 0)
updateSliderInput(session, 'sdg2_11', value = 0)
updateSliderInput(session, 'sdg2_12', value = 0)
updateSliderInput(session, 'sdg2_13', value = 0)
updateSliderInput(session, 'sdg2_14', value = 0)
updateSliderInput(session, 'sdg2_15', value = 0)
updateSliderInput(session, 'sdg2_16', value = 0)
updateSliderInput(session, 'sdg2_17', value = 0)
updateSliderInput(session, 'sdg2_18', value = 0)
updateSliderInput(session, 'sdg2_19', value = 0)
updateSliderInput(session, 'sdg2_20', value = 0)
updateSliderInput(session, 'sdg2_21', value = 0)
updatePrettyCheckboxGroup(session, 'cod_target', selected = lemur::data_app_input$cause_name)
})

Expand Down
Loading

0 comments on commit 8bda3c1

Please sign in to comment.