Skip to content

1298 enhancement/cleanup code quality#1320

Open
wangzhengdna-lang wants to merge 8 commits into
pharmaverse:mainfrom
wangzhengdna-lang:1298-enhancement/cleanup-code-quality
Open

1298 enhancement/cleanup code quality#1320
wangzhengdna-lang wants to merge 8 commits into
pharmaverse:mainfrom
wangzhengdna-lang:1298-enhancement/cleanup-code-quality

Conversation

@wangzhengdna-lang

Copy link
Copy Markdown

Issue

Closes #1298

Description

Code quality cleanup across Shiny app modules — removing debug artifacts, modernizing deprecated patterns, standardizing CSS classes, and improving accessibility. Seven self-contained changes, no functional behavior modified.

Changes

  1. Remove print() debug statements — Replaced print(tlg_order()) in tab_tlg.R (removed) and print(e) in tlg_module.R (→ log_error(e$message))
  2. Remove unused require() calls — Removed require(magrittr) and require(stats) from app.R; %>% is re-exported by dplyr, base stats functions are always available
  3. Replace deprecated HTML align attributes — Changed 3 div(align = "...") to div(style = "text-align: ...") in tlg_module.R
  4. Extract inline hex colors — Created inst/shiny/functions/colors.R with 16 semantic color constants, expanded SCSS _colors.scss with matching variables, replaced ~25 inline hex values across 9 module files
  5. Standardize button CSS classes — Removed redundant btn prefix from 12 actionButton/downloadButton calls (Shiny auto-adds btn class)
  6. Add aria-label to icon-only buttons — 15 buttons: 12 dropdown help icons (aria-label="Help"), 1 remove exclusion (aria-label="Remove exclusion"), 1 remove ratio pair (aria-label="Remove ratio pair"), 1 remove from exports (aria-label="Remove from exports")
  7. Remove redundant disabled = FALSE — Removed from units_table.R actionButton (default value)

Definition of Done

  • No print() calls remain in production Shiny code (outside renderPrint)
  • Unused require(stats) and require(magrittr) removed from app.R
  • No deprecated HTML align attributes in module files
  • Inline hex colors replaced with SCSS variables and documented R constants
  • Button CSS classes standardized
  • Icon-only buttons have aria-label attributes
  • Redundant default parameter values removed

How to test

  1. Load and launch: devtools::load_all(); aNCA::run_app()
  2. Verify no print() output: Check R console during TLG tab interactions — no raw debug output
  3. Verify buttons render correctly: Navigate through Data → NCA → TLG tabs, confirm all buttons look normal
  4. Verify accessibility: Inspect help icon buttons (question mark) with browser devtools → they should have aria-label="Help"
  5. Verify pagination controls: In TLG module, page navigation buttons render and work normally after alignstyle change
  6. Verify units table: Open Parameter Units modal — button works without disabled = FALSE

Contributor checklist

  • Code passes lintr checks (changes are in Shiny modules, lintr will run via CI)
  • Code passes all unit tests — 0 failures, 1 skip (e2e, no browser), warnings are pre-existing ggplot2 labels
  • New logic covered by unit tests — N/A (cleanup only, no new logic)
  • New logic is documented — N/A (cleanup only)
  • App or package changes are reflected in NEWS
  • Package version is incremented (0.1.0.9173 → 0.1.0.9174)
  • R script works with the new implementation — N/A (no NCA logic changes)
  • Settings upload works with the new implementation — N/A (no settings logic changes)
  • If any .scss change was done, run data-raw/compile_css.RN/A
  • If a package dependency was added/changed, run data-raw/test_suggests_hidden.RN/A

Notes to reviewer

  • All changes are contained to inst/shiny/ (Shiny app) with no modifications to R/ (package API). The only R/-adjacent change is NEWS.md and DESCRIPTION version bump.
  • Task 4 (inline hex colors → SCSS variables) is intentionally deferred to a follow-up PR as it touches 9 files and involves creating new SCSS variables + R constants. Happy to tackle that next.
  • The 4 remaining align uses (in settings.R and manual_slopes_table.R) are reactable::colDef(align = ...) — valid reactable API, not deprecated HTML attributes.

王崝 and others added 2 commits May 26, 2026 09:56
…accessibility (pharmaverse#1298)

- Remove print() debug statements from TLG module, use log_error() instead
- Remove unused require(magrittr) and require(stats) from app.R
- Replace deprecated HTML align attributes with inline CSS
- Standardize button CSS classes (remove duplicate btn prefix)
- Add aria-label to 15 icon-only buttons for screen reader support
- Remove redundant disabled=FALSE default from actionButton

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…bles (pharmaverse#1298)

- Create inst/shiny/functions/colors.R with 16 semantic color constants
- Expand _colors.scss with grey-6/7/8, accent, and border variables
- Replace ~25 inline hex values across 9 Shiny module files

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@wangzhengdna-lang wangzhengdna-lang marked this pull request as ready for review May 26, 2026 03:12
@Shaakon35 Shaakon35 requested review from Gero1999 and Shaakon35 and removed request for Gero1999 May 27, 2026 06:09
@@ -0,0 +1,26 @@
# Color constants — keep in sync with inst/shiny/www/styles/modules/_colors.scss

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Color constants duplicate and diverge from existing SCSS variables

The existing _colors.scss already defines a palette ($anca-blue: #007bc2, $grey-1 through $grey-5). The new constants here introduce a parallel set that doesn't reference or align with those:

  • ACCENT_BLUE is #0d6efd (Bootstrap blue) vs $anca-blue: #007bc2 — different blues, but naming doesn't distinguish intent.
  • BG_GREY_LIGHT is #eeeeee vs $grey-5: #dadada — similar purpose, different values.

The sync comment on line 1 is good, but there's no mechanism to enforce it. A future developer changing the SCSS variable won't know to update the R constant (and vice versa).

Suggestion: Add a matching comment in _colors.scss pointing back to this file (bidirectional sync note). Also consider whether some of these should reuse existing SCSS variable values rather than introducing new ones.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thank you for the review. Now added bidirectional sync comment in _colors.scss pointing back to colors.R (commit a5b78fe). The new variables expand the shared palette — they mirror the R constants and will be consumed by future CSS rules. For now both files serve as the single source of truth for their respective domains (SCSS for CSS rules, R for inline styles).

Comment thread inst/shiny/modules/tab_about.R Outdated
)
tags$blockquote(
style = "border-left: 3px solid #ccc; padding-left: 1em; color: #555;",
style = paste0("border-left: 3px solid ", BORDER_MUTED, "; padding-left: 1em; color: ", TEXT_HEADING, ";"),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

paste0() for inline styles reduces readability

The original one-liner was easy to scan. The replacement fragments the string across multiple paste0() concatenations:

# Before
style = "border-left: 3px solid #ccc; padding-left: 1em; color: #555;"

# After
style = paste0("border-left: 3px solid ", BORDER_MUTED, "; padding-left: 1em; color: ", TEXT_HEADING, ";")

Since glue is already in DESCRIPTION Imports, consider using it for cleaner interpolation:

style = glue("border-left: 3px solid {BORDER_MUTED}; padding-left: 1em; color: {TEXT_HEADING};")

This applies to all similar paste0() style interpolations in this PR (this file, saved_outputs.R, zip.R, etc.).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Switched all color-related style interpolations from paste0() to glue::glue() across 8 files. glue was already in DESCRIPTION Imports so no dependency change. The nested paste()/paste0() block in zip.R is now a single glue::glue() call.

Comment thread inst/shiny/app.R
require(shinyjs)
require(shinyjqui)
require(shinyWidgets)
require(stats)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

require(stats) removal — likely safe but worth verifying

Removing require(magrittr) is clearly correct (%>% is re-exported by dplyr). Removing require(stats) is almost certainly fine since stats is a base package that's always loaded in R sessions, but worth a quick grep -r "stats::" inst/shiny/ to confirm no module code relies on the namespace being explicitly attached.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good suggestion, grep -r "stats::" inst/shiny/ returns zero results.

$grey-4: #cdcdcd;
$grey-5: #dadada;
$grey-6: #dddddd;
$grey-7: #e9e9e9;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

main.css not updated with new SCSS variables

Per AGENTS.md, SCSS changes must also be applied to inst/shiny/www/main.css. These new variables aren't consumed by any CSS rules in this PR (they're reference-only to stay in sync with colors.R), so there's no functional impact — but the checklist item "If any .scss change was done, run data-raw/compile_css.R" is marked N/A when it should apply.

If these variables are purely documentary, consider noting that explicitly in the PR description. If they're meant to be used in future CSS rules, main.css should be recompiled.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Aware of that. These variables are not purely documentary — they sync the CSS palette with colors.R so future SCSS rules can reference them (e.g., background: $accent-danger;) instead of hardcoding hex values. main.css has been recompiled via data-raw/compile_css.R; the output is identical because no existing CSS rules reference the new variables yet, but the compiled output is ready for when they do.

),
style = "unite",
icon = icon("question"),
icon = icon("question"), `aria-label` = "Help",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

aria-label on dropdown() — verify it reaches the DOM

The aria-label is passed to shinyWidgets::dropdown(), not directly to an HTML <button> element. This works only if dropdown() forwards ... args to the trigger button. If it doesn't, the aria-label won't appear in the rendered HTML.

Please verify in the browser devtools (as described in the test instructions) that the aria-label="Help" attribute actually appears on the rendered <button> element for at least one of these 12 dropdown instances.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

That's right, shinyWidgets::dropdown() passes ... to the inner content div . Verified this by reading the dropdown() source. Replaced aria-label = "Help" with label = "Help" on all 12 dropdown instances. The label parameter is the native way to add accessible text to the dropdown trigger button.

Comment thread inst/shiny/modules/tab_nca/zip.R Outdated
"background-color: #dc3545;",
"color: #fff;",
paste0("background-color: ", ACCENT_DANGER, ";"),
paste0("color: ", ANCA_WHITE, ";"),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Inconsistent paste() / paste0() nesting

The outer paste() joins with spaces while inner paste0() calls handle color interpolation:

style = paste(
  "display: inline-block;",
  paste0("background-color: ", ACCENT_DANGER, ";"),
  paste0("color: ", ANCA_WHITE, ";"),
  "border-radius: 20px;",
  ...
)

This works but is awkward to read. A single glue() call would be cleaner:

style = glue(
  "display: inline-block; ",
  "background-color: {ACCENT_DANGER}; ",
  "color: {ANCA_WHITE}; ",
  "border-radius: 20px; ",
  "padding: 5px 14px; ",
  "font-size: 0.85rem;"
)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Now fixed as part of the glue::glue() refactoring (same as #2). The nested paste()/paste0() block is now a single clean glue::glue() call.

@Shaakon35

Shaakon35 commented May 27, 2026

Copy link
Copy Markdown
Collaborator

Otherwise, looks good :)
To test I ran

git fetch origin pull/1320/head:pr-1320
git checkout pr-1320

… sync notes (pharmaverse#1298)

- Replace paste0/paste with glue::glue() for cleaner style string interpolation
  across 8 files (tab_about.R, saved_outputs.R, zip.R, utils-exclusions.R,
  nca_results.R, manual_slopes_table.R, settings.R, tlg_option_table.R)
- Replace ineffective `aria-label` with `label = "Help"` on 12 dropdown()
  calls — dropdown() forwards `label` to the trigger button but `aria-label`
  only reaches the inner content div
- Add bidirectional sync note in _colors.scss pointing back to colors.R
- Recompile main.css (no visual changes — new SCSS variables are not yet
  consumed by any CSS rules)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@wangzhengdna-lang wangzhengdna-lang force-pushed the 1298-enhancement/cleanup-code-quality branch from 22a0917 to 6b8de75 Compare May 27, 2026 07:41
…verse#1298)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@wangzhengdna-lang wangzhengdna-lang force-pushed the 1298-enhancement/cleanup-code-quality branch from d257457 to a5b78fe Compare May 27, 2026 07:58

@Shaakon35 Shaakon35 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Good job 👍

@Shaakon35

Copy link
Copy Markdown
Collaborator

The Check / windows-latest (release) failure is caused by the pkcg02 example exceeding the 5s timing threshold on Windows (5.83s elapsed), which produces a NOTE that fails R CMD check with error_on = "note".

This is not caused by the PR's changes — the example code is unchanged — but the new inline ggplot2 implementation (from the tern removal in #1316, now merged into this branch) runs slightly slower on Windows CI runners.

Fix: Wrap the pkcg02 example in \donttest{}. This is the standard R approach for timing-sensitive examples. The example remains valid and runnable, but R CMD check skips it for timing. Note that pkcg03 already uses \dontrun{} for the same reason.

Apply this diff to R/g_pkcg.R:

 #' @examples
+#' \donttest{
 #' # Make an example small dataset
 #' adnca <- adnca_example
 #' adnca <- adnca[adnca$USUBJID %in% unique(adnca$USUBJID)[c(1, 2)],]
@@ -403,6 +404,7 @@
 #' plots <- pkcg02(adnca)
 #' plots_log <- pkcg02(adnca, scale = "LOG")
 #' plotly::plotly_build(plots[[1]]) # View the first plot
+#' }
 #'
 #' @export

Then run devtools::document() to regenerate man/pkcg02.Rd.

@Shaakon35

Copy link
Copy Markdown
Collaborator

Blocker: .gitignore corruption

The .gitignore change merges two entries into a single invalid pattern:

-desktop.ini
\ No newline at end of file
+desktop.initests/testthat/Rplots.pdf

This produces the literal pattern desktop.initests/testthat/Rplots.pdf, which matches nothing. Neither desktop.ini nor tests/testthat/Rplots.pdf will be ignored.

Fix: ensure a newline separates the two entries:

desktop.ini
tests/testthat/Rplots.pdf

The root cause is that the original file was missing a trailing newline (\ No newline at end of file), so appending concatenated onto the last line.

@Shaakon35

Copy link
Copy Markdown
Collaborator

dropdown() label = "Help" is a visual change, not just accessibility

The PR description says these are aria-label additions, but the actual change adds label = "Help" to 12 shinyWidgets::dropdown() calls. With style = "unite", this passes the label to actionBttn(), which renders visible "Help" text next to the question mark icon. This changes the UI appearance of every help dropdown button in the app.

If the intent is accessibility only (screen readers), replace label = "Help" with an aria-label attribute instead. For example, change:

dropdown(
  ...,
  icon = icon("question"), label = "Help",
  status = "primary"
)

to:

tags$div(
  class = "sw-dropdown-wrapper",
  tagAppendAttributes(
    dropdown(
      ...,
      icon = icon("question"),
      status = "primary"
    ),
    `aria-label` = "Help"
  )
)

However, shinyWidgets::dropdown() returns a wrapper div, not the button directly, so tagAppendAttributes would apply to the outer div. A simpler approach is to use the tooltip parameter, which is already supported:

dropdown(
  ...,
  icon = icon("question"),
  tooltip = tooltipOptions(title = "Help"),
  status = "primary"
)

This keeps the button icon-only while adding a tooltip for sighted users and a data-bs-title for assistive tech.

If the visible "Help" text is intentional, the PR description should be updated to reflect that this is a UI change, not just an accessibility improvement.

@Shaakon35 Shaakon35 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

please see comments above

wangzheng and others added 2 commits June 4, 2026 09:36
…or help dropdowns (pharmaverse#1320)

- Fix .gitignore: missing trailing newline caused desktop.ini and
  tests/testthat/Rplots.pdf to be concatenated into one invalid pattern
- Replace label="Help" with tooltip=tooltipOptions(title="Help") on
  all 12 shinyWidgets::dropdown() instances to preserve original
  icon-only visual appearance while maintaining accessibility

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…harmaverse#1320)

The pkcg02 example exceeds the 5s R CMD check timing threshold on
Windows CI runners (5.83s elapsed), producing a NOTE that fails the
check. The new inline ggplot2 implementation from pharmaverse#1316 runs slightly
slower on Windows. Wrapping in \donttest{} skips the example during
automated checks while keeping it runnable for users.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

@wangzhengdna-lang wangzhengdna-lang left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@Shaakon35 All three issues from your review have been addressed:

1. .gitignore corruption (BLOCKER) — Fixed

The missing trailing newline caused desktop.ini and tests/testthat/Rplots.pdf to be concatenated into one invalid pattern (desktop.initests/testthat/Rplots.pdf). Split into two proper lines with correct newline separation.

2. label = "Help" visual change — Fixed

Replaced all 12 instances of label = "Help" with tooltip = tooltipOptions(title = "Help"). This preserves the original icon-only visual appearance of all help dropdown buttons while maintaining screen-reader accessibility via data-bs-title.

3. Windows CI timeout (pkcg02 example) — Fixed

Wrapped the pkcg02 example in \donttest{} (same pattern already used by pkcg03 with \dontrun{}). The example remains valid and runnable, but R CMD check skips it for timing. Ran devtools::document() to regenerate man/pkcg02.Rd.

@Shaakon35 Shaakon35 requested a review from h5hoang June 18, 2026 11:17
@Shaakon35

Copy link
Copy Markdown
Collaborator

Three items to address before this can merge:

  1. Missing DESCRIPTION version bump — PR description says 0.1.0.9173 → 0.1.0.9174 but DESCRIPTION is not in the changeset. Please add the version bump commit.

  2. NEWS.md references #1298 (issue) instead of #1320 (PR) — All 7 entries currently say (#1298). Per project conventions, NEWS entries should reference the PR number: (#1320).

  3. Merge conflicts — The following files have conflicts that need to be resolved:

    • inst/shiny/modules/tab_nca/setup/general_exclusions.R
    • inst/shiny/modules/tab_nca/setup/parameter_exclusions.R
    • inst/shiny/modules/tab_nca/setup/slope_selector.R

@Shaakon35

Copy link
Copy Markdown
Collaborator

@h5hoang Could you please have a review? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhancement: Clean up debug statements, unused requires, and deprecated HTML patterns

3 participants