Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

553 introduce internal log_shiny_input_changes function #84

Merged
merged 27 commits into from
Jun 19, 2024

Conversation

m7pr
Copy link
Contributor

@m7pr m7pr commented Jun 18, 2024

Part of https://github.com/insightsengineering/coredev-tasks/issues/553 and https://github.com/insightsengineering/coredev-tasks/issues/568

Function is an extended copy of logger::log_shiny_input_changes but curated to our needs.

Currently features comparison to what's included in logger

  • we do not provide an initialization message with the list of input values at start
  • created excluded_patterns parameter that allows to exclude inputs from logging based on grep patterns - we are excluding plot resizing by default
  • usage of session object to detect that the session is a mocked session
  • extension of logs with a namespace name

@m7pr m7pr added the core label Jun 18, 2024
Copy link
Contributor

github-actions bot commented Jun 18, 2024

CLA Assistant Lite bot ✅ All contributors have signed the CLA

@m7pr
Copy link
Contributor Author

m7pr commented Jun 18, 2024

I have read the CLA Document and I hereby sign the CLA

@m7pr
Copy link
Contributor Author

m7pr commented Jun 18, 2024

recheck

@m7pr m7pr requested a review from pawelru June 18, 2024 14:03
Copy link
Contributor

github-actions bot commented Jun 18, 2024

badge

Code Coverage Summary

Filename                       Stmts    Miss  Cover    Missing
---------------------------  -------  ------  -------  ---------
R/log_shiny_input_changes.R       24      24  0.00%    41-69
R/register_handlers.R             39       0  100.00%
R/register_logger.R               56       1  98.21%   115
R/supress_logs.R                   5       5  0.00%    17-21
R/utils.R                         20       0  100.00%
TOTAL                            144      30  79.17%

Diff against main

Filename                       Stmts    Miss  Cover
---------------------------  -------  ------  --------
R/log_shiny_input_changes.R      +24     +24  +100.00%
TOTAL                            +24     +24  -15.83%

Results for commit: 049e630

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

Copy link
Contributor

github-actions bot commented Jun 18, 2024

Unit Tests Summary

 1 files   3 suites   0s ⏱️
25 tests 25 ✅ 0 💤 0 ❌
37 runs  37 ✅ 0 💤 0 ❌

Results for commit 049e630.

♻️ This comment has been updated with latest results.

DESCRIPTION Show resolved Hide resolved
@m7pr
Copy link
Contributor Author

m7pr commented Jun 18, 2024

@pawelru if we want to have our own implementation of log_input_shiny_changes that has nothing to do with the logger version then there is a lot of places where this function can get improved just to fit our needs

m7pr and others added 4 commits June 18, 2024 17:30
Merge branch '553_log_shiny_input_changes@main' of https://github.com/insightsengineering/teal.logger into 553_log_shiny_input_changes@main

# Conflicts:
#	R/log_shiny_input_changes.R
Co-authored-by: Pawel Rucki <[email protected]>
Signed-off-by: Marcin <[email protected]>
DESCRIPTION Show resolved Hide resolved
@m7pr
Copy link
Contributor Author

m7pr commented Jun 19, 2024

For a simple input change in UI I see 5 logs displayed in the console

[TRACE] 2024-06-19 09:55:27.7176 pid:24656 token:[31ad1df8] teal.modules.clinical teal-main_ui-root-adae_analysis-module Shiny input change detected in fill-dataset_ADSL_singleextract-select_open: NULL -> TRUE
[TRACE] 2024-06-19 09:55:35.0600 pid:24656 token:[31ad1df8] teal.modules.clinical teal-main_ui-root-adae_analysis-module Shiny input change detected in fill-dataset_ADSL_singleextract-select: SEX -> ACTARM
[TRACE] 2024-06-19 09:55:35.0645 pid:24656 token:[31ad1df8] teal.modules.clinical teal-main_ui-root-adae_analysis-module Shiny input change detected in fill-dataset_ADSL_singleextract-select_open: NULL -> TRUE
[TRACE] 2024-06-19 09:55:35.0780 pid:24656 token:[31ad1df8] teal.modules.clinical teal-main_ui-root-adae_analysis-module Shiny input change detected in fill-dataset_ADSL_singleextract-select: SEX -> ACTARM
[TRACE] 2024-06-19 09:55:35.0830 pid:24656 token:[31ad1df8] teal.modules.clinical teal-main_ui-root-adae_analysis-module Shiny input change detected in fill-dataset_ADSL_singleextract-select_open: NULL -> FALSE

Where first two and another two are the same, which made me think we have some duplicates. This was not the case while this feature was using utils::assignInMyNamespace() and utils::assignInNamespace(). I think this is due how the shiny_input_values is treated in the shiny::observer. Will try to bring utils::assignInMyNamespace() and utils::assignInNamespace() back to see if this removed duplicated logs.

@m7pr
Copy link
Contributor Author

m7pr commented Jun 19, 2024

When I brought back the usage of utils::assignInMyNamespace() and utils::assignInNamespace() I do no longer see duplicated logs, and we only see 3 logs for one single input change

[TRACE] 2024-06-19 10:06:20.3276 pid:17336 token:[37e75bcf] teal.modules.clinical teal-main_ui-root-adae_analysis-module Shiny input change detected in fill-dataset_ADSL_singleextract-select_open: NULL -> TRUE
[TRACE] 2024-06-19 10:06:23.9033 pid:17336 token:[37e75bcf] teal.modules.clinical teal-main_ui-root-adae_analysis-module Shiny input change detected in fill-dataset_ADSL_singleextract-select: SEX -> RACE
[TRACE] 2024-06-19 10:06:24.3814 pid:17336 token:[37e75bcf] teal.modules.clinical teal-main_ui-root-adae_analysis-module Shiny input change detected in fill-dataset_ADSL_singleextract-select_open: TRUE -> FALSE

Surprisingly I see many more logs that poped-up during this input change

[TRACE] 2024-06-19 10:06:22.0966 pid:17336 token:[37e75bcf] teal.transform data_extract_read_srv@2 dataname: ADSL; select: RACE.
[TRACE] 2024-06-19 10:06:22.1528 pid:17336 token:[37e75bcf] teal.transform merge_datasets called with: ADSL, ADAE datasets; x, fill, x_facet, y_facet selectors; dplyr::full_join merge function.
[TRACE] 2024-06-19 10:06:22.1560 pid:17336 token:[37e75bcf] teal.transform merge_selectors called with: x, fill, x_facet, y_facet selectors.
[TRACE] 2024-06-19 10:06:22.1596 pid:17336 token:[37e75bcf] teal.transform get_dplyr_call_data called with: x, x_facet selectors.
[TRACE] 2024-06-19 10:06:22.1628 pid:17336 token:[37e75bcf] teal.transform get_merge_key_grid called with: x, x_facet selectors.
[TRACE] 2024-06-19 10:06:22.1808 pid:17336 token:[37e75bcf] teal.transform get_merge_key_pair called with: x, x selectors; STUDYID, USUBJID keys.
[TRACE] 2024-06-19 10:06:22.1838 pid:17336 token:[37e75bcf] teal.transform get_dropped_filters called with x selector.
[TRACE] 2024-06-19 10:06:22.1863 pid:17336 token:[37e75bcf] teal.transform get_merge_key_pair returns STUDYID, USUBJID merge keys.
[TRACE] 2024-06-19 10:06:22.1973 pid:17336 token:[37e75bcf] teal.transform get_merge_key_pair called with: x, x_facet selectors; STUDYID, USUBJID keys.
[TRACE] 2024-06-19 10:06:22.2010 pid:17336 token:[37e75bcf] teal.transform get_merge_key_pair returns STUDYID, USUBJID merge keys.
[TRACE] 2024-06-19 10:06:22.2109 pid:17336 token:[37e75bcf] teal.transform get_merge_key_pair called with: x_facet, x selectors; STUDYID, USUBJID keys.
[TRACE] 2024-06-19 10:06:22.2159 pid:17336 token:[37e75bcf] teal.transform get_merge_key_pair returns STUDYID, USUBJID merge keys.
[TRACE] 2024-06-19 10:06:22.2251 pid:17336 token:[37e75bcf] teal.transform get_merge_key_pair called with: x_facet, x_facet selectors; STUDYID, USUBJID, ASTDTM, AETERM, AESEQ keys.
[TRACE] 2024-06-19 10:06:22.2287 pid:17336 token:[37e75bcf] teal.transform get_dropped_filters called with x_facet selector.
[TRACE] 2024-06-19 10:06:22.2311 pid:17336 token:[37e75bcf] teal.transform get_merge_key_pair returns STUDYID, USUBJID, ASTDTM, AETERM, AESEQ merge keys.
[TRACE] 2024-06-19 10:06:22.2406 pid:17336 token:[37e75bcf] teal.transform get_dplyr_call called with: ADSL, ADAE datasets; x, x_facet selectors.
[TRACE] 2024-06-19 10:06:22.2463 pid:17336 token:[37e75bcf] teal.transform get_filter_call called with: ADSL dataset;  filters.
[TRACE] 2024-06-19 10:06:22.2496 pid:17336 token:[37e75bcf] teal.transform get_select_call called with: STUDYID, USUBJID, ACTARM, RACE columns.
[TRACE] 2024-06-19 10:06:22.2521 pid:17336 token:[37e75bcf] teal.transform get_rename_call called with: x selector; ACTARM, RACE renamed columns.
[TRACE] 2024-06-19 10:06:22.2551 pid:17336 token:[37e75bcf] teal.transform get_dplyr_call called with: ADSL, ADAE datasets; x, x_facet selectors.
[TRACE] 2024-06-19 10:06:22.2595 pid:17336 token:[37e75bcf] teal.transform get_filter_call called with: ADAE dataset;  filters.
[TRACE] 2024-06-19 10:06:22.2635 pid:17336 token:[37e75bcf] teal.transform get_select_call called with: STUDYID, USUBJID, AETOXGR, AESEV columns.
[TRACE] 2024-06-19 10:06:22.2658 pid:17336 token:[37e75bcf] teal.transform get_rename_call called with: x_facet selector; AETOXGR, AESEV renamed columns.
[TRACE] 2024-06-19 10:06:22.2681 pid:17336 token:[37e75bcf] teal.transform get_merge_call called with: x, x_facet selectors; dplyr::full_join merge function.
[TRACE] 2024-06-19 10:06:22.2707 pid:17336 token:[37e75bcf] teal.transform get_merge_key_i called with x, x_facet selectors; idx = 2.
[TRACE] 2024-06-19 10:06:22.2738 pid:17336 token:[37e75bcf] teal.transform get_merge_key_i returns STUDYID USUBJID unique keys.
[TRACE] 2024-06-19 10:06:22.2793 pid:17336 token:[37e75bcf] teal.transform parse_merge_key_i called with STUDYID USUBJID keys.
[TRACE] 2024-06-19 10:06:22.2835 pid:17336 token:[37e75bcf] teal.transform get_relabel_cols called with: x, fill, x_facet, y_facet columns_source.
[TRACE] 2024-06-19 10:06:22.2857 pid:17336 token:[37e75bcf] teal.transform get_anl_relabel_call called with: x, fill, x_facet, y_facet columns_source; ANL merged dataset.
[TRACE] 2024-06-19 10:06:22.2934 pid:17336 token:[37e75bcf] teal.transform get_relabel_call called with: Description of Actual Arm Race Analysis Toxicity Grade Severity/Intensity labels.
[TRACE] 2024-06-19 10:06:22.2973 pid:17336 token:[37e75bcf] teal.transform merge_datasets merge code executed resulting in ANL dataset.
[TRACE] 2024-06-19 10:06:22.3974 pid:17336 token:[37e75bcf] teal.transform get_anl_relabel_call called with: x, fill, x_facet, y_facet columns_source; counts merged dataset.
[TRACE] 2024-06-19 10:06:22.4046 pid:17336 token:[37e75bcf] teal.transform get_relabel_call called with: Description of Actual Arm Race Analysis Toxicity Grade Severity/Intensity labels.

@m7pr
Copy link
Contributor Author

m7pr commented Jun 19, 2024

But this is the regular amount of logs that we have on TRACE level, when log_shiny_input_changes is commented out and not used.

App for testing:
options(teal.log_level = "TRACE", teal.show_js_log = TRUE)

library(nestcolor)
library(dplyr)
#library(teal.modules.clinical)
devtools::load_all("../teal.logger/")
devtools::load_all(".")

ADSL <- tmc_ex_adsl %>%
  mutate(ITTFL = factor("Y") %>%
           with_label("Intent-To-Treat Population Flag"))
ADAE <- tmc_ex_adae %>%
  filter(!((AETOXGR == 1) & (AESEV == "MILD") & (ARM == "A: Drug X")))

app <- init(
  data = cdisc_data(
    ADSL = ADSL,
    ADAE = ADAE,
    code = "ADSL <- tmc_ex_adsl %>%
              mutate(ITTFL = factor(\"Y\") %>%
              with_label(\"Intent-To-Treat Population Flag\"))
            ADAE <- tmc_ex_adae %>%
              filter(!((AETOXGR == 1) & (AESEV == \"MILD\") & (ARM == \"A: Drug X\")))"
  ),
  modules = modules(
    tm_g_barchart_simple(
      label = "ADAE Analysis",
      x = data_extract_spec(
        dataname = "ADSL",
        select = select_spec(
          choices = variable_choices(
            ADSL,
            c(
              "ARM", "ACTARM", "SEX",
              "RACE", "ITTFL", "SAFFL", "STRATA2"
            )
          ),
          selected = "ACTARM",
          multiple = FALSE
        )
      ),
      fill = list(
        data_extract_spec(
          dataname = "ADSL",
          select = select_spec(
            choices = variable_choices(
              ADSL,
              c(
                "ARM", "ACTARM", "SEX",
                "RACE", "ITTFL", "SAFFL", "STRATA2"
              )
            ),
            selected = "SEX",
            multiple = FALSE
          )
        ),
        data_extract_spec(
          dataname = "ADAE",
          select = select_spec(
            choices = variable_choices(ADAE, c("AETOXGR", "AESEV", "AESER")),
            selected = NULL,
            multiple = FALSE
          )
        )
      ),
      x_facet = list(
        data_extract_spec(
          dataname = "ADAE",
          select = select_spec(
            choices = variable_choices(ADAE, c("AETOXGR", "AESEV", "AESER")),
            selected = "AETOXGR",
            multiple = FALSE
          )
        ),
        data_extract_spec(
          dataname = "ADSL",
          select = select_spec(
            choices = variable_choices(
              ADSL,
              c(
                "ARM", "ACTARM", "SEX",
                "RACE", "ITTFL", "SAFFL", "STRATA2"
              )
            ),
            selected = NULL,
            multiple = FALSE
          )
        )
      ),
      y_facet = list(
        data_extract_spec(
          dataname = "ADAE",
          select = select_spec(
            choices = variable_choices(ADAE, c("AETOXGR", "AESEV", "AESER")),
            selected = "AESEV",
            multiple = FALSE
          )
        ),
        data_extract_spec(
          dataname = "ADSL",
          select = select_spec(
            choices = variable_choices(
              ADSL,
              c(
                "ARM", "ACTARM", "SEX",
                "RACE", "ITTFL", "SAFFL", "STRATA2"
              )
            ),
            selected = NULL,
            multiple = FALSE
          )
        )
      )
    )
  )
)
if (interactive()) {
  shinyApp(app$ui, app$server)
}

@m7pr m7pr requested a review from pawelru June 19, 2024 09:37
Copy link
Contributor

@pawelru pawelru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that this is good to go 👍

@m7pr m7pr merged commit 44858e7 into main Jun 19, 2024
30 checks passed
@m7pr m7pr deleted the 553_log_shiny_input_changes@main branch June 19, 2024 09:53
@github-actions github-actions bot locked and limited conversation to collaborators Jun 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants