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

Custom rendering to provide manual ticks when there is <10 ticks #319

Merged
merged 18 commits into from
Oct 28, 2024

Conversation

vedhav
Copy link
Contributor

@vedhav vedhav commented Oct 10, 2024

Closes #133

Example app to test:

devtools::load_all()
# Example using ADaM structure analysis dataset.
data <- teal_data()
data <- within(data, {
  library(dplyr)
  library(nestcolor)
  library(stringr)

  # use non-exported function from goshawk
  h_identify_loq_values <- getFromNamespace("h_identify_loq_values", "goshawk")

  # original ARM value = dose value
  arm_mapping <- list(
    "A: Drug X" = "150mg QD",
    "B: Placebo" = "Placebo",
    "C: Combination" = "Combination"
  )
  set.seed(1)
  ADSL <- rADSL
  ADLB <- rADLB
  var_labels <- lapply(ADLB, function(x) attributes(x)$label)
  ADLB <- ADLB %>%
    mutate(
      AVISITCD = case_when(
        AVISIT == "SCREENING" ~ "SCR",
        AVISIT == "BASELINE" ~ "BL",
        grepl("WEEK", AVISIT) ~ paste("W", str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")),
        TRUE ~ as.character(NA)
      ),
      AVISITCDN = case_when(
        AVISITCD == "SCR" ~ -2,
        AVISITCD == "BL" ~ 0,
        grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)),
        TRUE ~ as.numeric(NA)
      ),
      AVISITCD = factor(AVISITCD) %>% reorder(AVISITCDN),
      TRTORD = case_when(
        ARMCD == "ARM C" ~ 1,
        ARMCD == "ARM B" ~ 2,
        ARMCD == "ARM A" ~ 3
      ),
      ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))]),
      ARM = factor(ARM) %>% reorder(TRTORD),
      ACTARM = as.character(arm_mapping[match(ACTARM, names(arm_mapping))]),
      ACTARM = factor(ACTARM) %>% reorder(TRTORD),
      ANRLO = 50,
      ANRHI = 75
    ) %>%
    rowwise() %>%
    group_by(PARAMCD) %>%
    mutate(LBSTRESC = ifelse(
      USUBJID %in% sample(USUBJID, 1, replace = TRUE),
      paste("<", round(runif(1, min = 25, max = 30))), LBSTRESC
    )) %>%
    mutate(LBSTRESC = ifelse(
      USUBJID %in% sample(USUBJID, 1, replace = TRUE),
      paste(">", round(runif(1, min = 70, max = 75))), LBSTRESC
    )) %>%
    ungroup()

  attr(ADLB[["ARM"]], "label") <- var_labels[["ARM"]]
  attr(ADLB[["ACTARM"]], "label") <- var_labels[["ACTARM"]]
  attr(ADLB[["ANRLO"]], "label") <- "Analysis Normal Range Lower Limit"
  attr(ADLB[["ANRHI"]], "label") <- "Analysis Normal Range Upper Limit"

  # add LLOQ and ULOQ variables
  ALB_LOQS <- h_identify_loq_values(ADLB, "LOQFL")
  ADLB <- left_join(ADLB, ALB_LOQS, by = "PARAM")
})

datanames <- c("ADSL", "ADLB")
datanames(data) <- datanames


join_keys(data) <- default_cdisc_join_keys[datanames]

app <- init(
  data = data,
  modules = modules(
    tm_g_gh_boxplot(
      label = "Box Plot",
      dataname = "ADLB",
      param_var = "PARAMCD",
      param = choices_selected(c("ALT", "CRP", "IGA"), "CRP"),
      yaxis_var = choices_selected(c("AVAL", "BASE", "CHG"), "AVAL"),
      xaxis_var = choices_selected(c("ACTARM", "ARM", "AVISITCD", "STUDYID"), "ARM"),
      facet_var = choices_selected(c("ACTARM", "ARM", "AVISITCD", "SEX"), "AVISITCD"),
      trt_group = choices_selected(c("ARM", "ACTARM"), "ARM"),
      loq_legend = TRUE,
      rotate_xlab = FALSE,
      hline_arb = c(60, 55),
      hline_arb_color = c("grey", "red"),
      hline_arb_label = c("default_hori_A", "default_hori_B"),
      hline_vars = c("ANRHI", "ANRLO", "ULOQN", "LLOQN"),
      hline_vars_colors = c("pink", "brown", "purple", "black"),
    )
  )
)

shinyApp(app$ui, app$server)

@vedhav vedhav added bug Something isn't working core labels Oct 10, 2024
@vedhav vedhav requested a review from m7pr October 10, 2024 12:09
R/toggleable_slider.R Outdated Show resolved Hide resolved
Copy link
Contributor

github-actions bot commented Oct 10, 2024

badge

Code Coverage Summary

Filename                                 Stmts    Miss  Cover    Missing
-------------------------------------  -------  ------  -------  ---------------------------------------------------------
R/tm_g_gh_boxplot.R                        345      30  91.30%   365, 371, 510-511, 519-542, 544-545
R/tm_g_gh_correlationplot.R                566     566  0.00%    227-903
R/tm_g_gh_density_distribution_plot.R      272     272  0.00%    135-460
R/tm_g_gh_lineplot.R                       557     557  0.00%    161-812
R/tm_g_gh_scatterplot.R                    254     254  0.00%    144-452
R/tm_g_gh_spaghettiplot.R                  319     319  0.00%    194-596
R/toggleable_slider.R                      112       7  93.75%   140-146
R/utils-arbitrary_lines.r                  125      14  88.80%   63, 74-77, 81, 93-96, 110, 114, 121, 125
R/utils-data_constraints.r                 190      61  67.89%   39, 57, 111-124, 126-140, 154, 177, 183, 202-228, 243-252
R/utils-maptrt.r                             9       9  0.00%    24-36
R/utils-templ_ui.r                          66      17  74.24%   2-7, 40-43, 73-79
R/utils.R                                   49      40  18.37%   12-19, 26, 60-112
R/zzz.R                                      2       2  0.00%    2-3
TOTAL                                     2866    2148  25.05%

Diff against main

Filename                                 Stmts    Miss  Cover
-------------------------------------  -------  ------  --------
R/tm_g_gh_boxplot.R                         -4    -319  +91.30%
R/tm_g_gh_correlationplot.R                +10     +10  +100.00%
R/tm_g_gh_density_distribution_plot.R       -2      -2  +100.00%
R/tm_g_gh_lineplot.R                        -5      -5  +100.00%
R/tm_g_gh_scatterplot.R                     +8      +8  +100.00%
R/tm_g_gh_spaghettiplot.R                   +3      +3  +100.00%
R/toggleable_slider.R                      -46    -151  +93.75%
R/utils-arbitrary_lines.r                    0    -111  +88.80%
R/utils-data_constraints.r                   0    -129  +67.89%
R/utils-templ_ui.r                           0     -49  +74.24%
R/utils.R                                    0      -9  +18.37%
TOTAL                                      -36    -754  +25.05%

Results for commit: 5990855

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

@m7pr
Copy link
Contributor

m7pr commented Oct 10, 2024

@vedhav The slider does not affect the output of the plot : ( plot Y-Axis should be reduced to the limits set in the slider

image

@vedhav
Copy link
Contributor Author

vedhav commented Oct 10, 2024

Ah, I can see why this could happen. Let me check.

@vedhav
Copy link
Contributor Author

vedhav commented Oct 10, 2024

@m7pr that bug is fixed. I stumbled upon another bug, When some inputs change (in the top widgets, like the Select an X-Axis Biomarker), the slider range is set again to new limits, currently this is not happening. I'm working on this case.

@vedhav vedhav requested a review from donyunardi October 11, 2024 13:29
@vedhav vedhav enabled auto-merge (squash) October 11, 2024 15:24
@donyunardi donyunardi disabled auto-merge October 11, 2024 15:30
Copy link
Contributor

@donyunardi donyunardi left a comment

Choose a reason for hiding this comment

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

Thanks for the work, @vedhav

I have couple findings:

  1. The plot and slider got reset to original value after clicking the Toggle button a few times:
Screen.Recording.2024-10-11.at.8.27.54.AM.mov

On 0:18 to 0:20, you can see the plot changes before I click the Toggle button.
This doesn't happen in main branch.

  1. When I changed the X-Axis Biomarker to ALT, the numbers in ticks are overlapping toward the end of the slider:

@vedhav vedhav requested a review from donyunardi October 15, 2024 15:45
@vedhav
Copy link
Contributor Author

vedhav commented Oct 16, 2024

@donyunardi Please have a look now. There was another reactivity issue, its getting harder and harder to maintain this, we might have to invest some time in implementing this as a component in teal.widgets.
The tick overlap is also fixed now.

@m7pr
Copy link
Contributor

m7pr commented Oct 16, 2024

guidelines for the review https://github.com/insightsengineering/coredev-tasks/issues/590

R/toggleable_slider.R Outdated Show resolved Hide resolved
R/toggleable_slider.R Outdated Show resolved Hide resolved
R/toggleable_slider.R Outdated Show resolved Hide resolved
R/toggleable_slider.R Outdated Show resolved Hide resolved
R/toggleable_slider.R Outdated Show resolved Hide resolved
R/toggleable_slider.R Outdated Show resolved Hide resolved
R/toggleable_slider.R Outdated Show resolved Hide resolved
R/toggleable_slider.R Outdated Show resolved Hide resolved
R/toggleable_slider.R Outdated Show resolved Hide resolved
R/toggleable_slider.R Outdated Show resolved Hide resolved
R/toggleable_slider.R Outdated Show resolved Hide resolved
vedhav and others added 2 commits October 28, 2024 19:36
Closes #321 

Changes:
1. The `toggle_slider_ui` and `toggle_slider_server` can only be used to
create dichotomous slider now. There was no instance of single value
slider created. So, there is no need to create it and increase the
complexity.
2. Removal of the `keep_range_slider_updated` in favor of
`keep_slider_state_updated` to keep the states updated based on other
widget inputs.
3. Updated the modules that uses this widget. Note that the
`tm_g_gh_lineplot` does not use the `keep_slider_state_updated` and
directly updates the state reactiveValues.

Check all the modules that use the `toggle_slider` module:

- [ ] `tm_g_gh_boxplot`
- [ ] `tm_g_gh_correlationplot`
- [ ] `tm_g_gh_density_distribution_plot`
- [ ] `tm_g_gh_lineplot`
- [ ] `tm_g_gh_spaghettiplot`
- [ ] `tm_g_gh_scatterplot `(deprecate in favor of
`tm_g_gh_correlationplot`)

---------

Co-authored-by: go_gonzo <[email protected]>
@vedhav vedhav requested a review from gogonzo October 28, 2024 14:09
@gogonzo gogonzo dismissed donyunardi’s stale review October 28, 2024 14:13

changes have been made

@vedhav vedhav enabled auto-merge (squash) October 28, 2024 14:13
Copy link
Contributor

github-actions bot commented Oct 28, 2024

Unit Tests Summary

 1 files   1 suites   56s ⏱️
 6 tests  6 ✅ 0 💤 0 ❌
12 runs  12 ✅ 0 💤 0 ❌

Results for commit 0be5c7f.

♻️ This comment has been updated with latest results.

Copy link
Contributor

@gogonzo gogonzo left a comment

Choose a reason for hiding this comment

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

Works as expected. Merge once R CMD check is fixed. Great job 💪

@vedhav vedhav merged commit 7907046 into main Oct 28, 2024
25 checks passed
@vedhav vedhav deleted the 133-improve-slider-ticks@main branch October 28, 2024 15:50
@github-actions github-actions bot locked and limited conversation to collaborators Oct 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UAT All X-Axis & Y-Axis Range Zooms
4 participants