Skip to content

Keep label when column is a factor#679

Merged
osenan merged 9 commits intomainfrom
missing_variable_label@main
Feb 25, 2026
Merged

Keep label when column is a factor#679
osenan merged 9 commits intomainfrom
missing_variable_label@main

Conversation

@osenan
Copy link
Copy Markdown
Contributor

@osenan osenan commented Feb 23, 2026

This fixes the issue on label display #611 for factors.

You can check the fix in this app:

library(teal)
library(teal.modules.general)

# Create sample data with different variable types
app <- init(
  data = teal_data(
    ADSL = within(teal.data::rADSL, {
      # Ensure we have different variable types for filtering
      STUDYID <- as.character(STUDYID)        # character
      CATEGORY <- factor(sample(paste0("Cat_", sprintf("%03d", 1:100)), nrow(teal.data::rADSL), replace = TRUE))
      
      # Add variable labels
      attr(STUDYID, "label") <- "Study Identifier"
      attr(CATEGORY, "label") <- "Category"
    }),
    ADTTE = within(teal.data::rADTTE, {
      STUDYID <- as.character(STUDYID)
      CATEGORY <- factor(sample(paste0("Cat_", sprintf("%03d", 1:100)), nrow(teal.data::rADTTE), replace = TRUE))
      
      # Add variable labels
      attr(STUDYID, "label") <- "Study Identifier"
      attr(CATEGORY, "label") <- "Category"
    }),
    code = "
      library(teal.data)
      
      ADSL <- within(teal.data::rADSL, {
        STUDYID <- as.character(STUDYID)
        CATEGORY <- factor(sample(paste0('Cat_', sprintf('%03d', 1:100)), nrow(teal.data::rADSL), replace = TRUE))
        
        attr(STUDYID, 'label') <- 'Study Identifier'
        attr(CATEGORY, 'label') <- 'Category'
      })
      
      ADTTE <- within(teal.data::rADTTE, {
        STUDYID <- as.character(STUDYID)
        CATEGORY <- factor(sample(paste0('Cat_', sprintf('%03d', 1:100)), nrow(teal.data::rADTTE), replace = TRUE))
        
        attr(STUDYID, 'label') <- 'Study Identifier'
        attr(CATEGORY, 'label') <- 'Category'
      })
    "
  ),
  modules = modules(
    # Module 1: Data Table - allows viewing and filtering data
    tm_data_table(
      label = "Data Table",
      variables_selected = list(
        ADSL = c("USUBJID", "SEX", "AGE", "RACE", "COUNTRY", "ARM", "RANDDT", "TRTSDT", "BMRKR1", "CATEGORY"),
        ADTTE = c("USUBJID", "PARAMCD", "ARM", "SEX", "AVAL", "CNSR", "EVENTDT", "CATEGORY")
      )
    ),
    # Module 2: Variable Browser - shows variable details and distributions
    tm_variable_browser(
      label = "Variable Browser"
    )
  ),
  title = "Simple Teal App with Multiple Variable Types",
  filter = teal_slices(
    # Pre-configure some filters to demonstrate different types
    teal_slice(dataname = "ADSL", varname = "STUDYID"),       # character
    teal_slice(dataname = "ADSL", varname = "CATEGORY")      # factor with 100 levels
  )
)

# Run the app
shinyApp(app$ui, app$server)

After installing this branch teal.slice
I've added a test for varlabels in general.

There is a PR with similar solution, but it does not have a test.
image

@osenan osenan requested a review from a team February 23, 2026 11:32
@osenan osenan added the core label Feb 23, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 23, 2026


🎉 Thank you for your contribution! Before this PR can be accepted, we require that you read and agree to our Contributor License Agreement.
You can digitally sign the CLA by posting a comment on this Pull Request in the format shown below. This agreement will apply to this PR as well as all future contributions on this repository.


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


osenan seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@osenan
Copy link
Copy Markdown
Contributor Author

osenan commented Feb 23, 2026

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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 23, 2026

badge

Code Coverage Summary

Filename                        Stmts    Miss  Cover    Missing
----------------------------  -------  ------  -------  -------------------------------------------------------------------------------------------------------------------------
R/calls_combine_by.R                7       0  100.00%
R/choices_labeled.R                23       1  95.65%   34
R/count_labels.R                  126       0  100.00%
R/filter_panel_api.R               27       1  96.30%   132
R/FilteredData-utils.R             58      17  70.69%   38-43, 139, 161-170
R/FilteredData.R                  522     118  77.39%   109, 138, 186, 325, 397, 484-493, 514, 532-590, 610-613, 657, 712-728, 873, 885-905
R/FilteredDataset-utils.R          23       1  95.65%   125
R/FilteredDataset.R               264       5  98.11%   49, 154, 189, 214-215
R/FilteredDatasetDataframe.R      123       3  97.56%   87, 148, 158
R/FilteredDatasetDefault.R         18       4  77.78%   104-117
R/FilteredDatasetMAE.R            133      15  88.72%   56, 118-123, 160-165, 169-170
R/FilterPanelAPI.R                 10       0  100.00%
R/FilterState-utils.R             101       2  98.02%   264, 294
R/FilterState.R                   366      21  94.26%   91, 155, 266-267, 273-274, 328, 330, 416, 632, 675-679, 698, 762-768, 779
R/FilterStateChoices.R            354      10  97.18%   325, 448-451, 563-566, 611
R/FilterStateDate.R               221      46  79.19%   233, 361-371, 382-387, 391-396, 404-419, 438-445
R/FilterStateDatettime.R          316     206  34.81%   269, 321-559
R/FilterStateEmpty.R               53      31  41.51%   89, 99-104, 117, 129-169
R/FilterStateExpr.R                81       1  98.77%   244
R/FilterStateLogical.R            201     149  25.87%   139, 161, 221, 225-414
R/FilterStateRange.R              411     121  70.56%   264, 386, 497-504, 507-517, 520, 531-537, 548-560, 564-574, 578-580, 593-619, 634-641, 644-651, 665-682, 717-722, 732-734
R/FilterStates-utils.R             70       7  90.00%   108, 127, 188-194
R/FilterStates.R                  379      19  94.99%   63, 92-96, 208, 425, 470, 559-563, 608, 726-729
R/FilterStatesDF.R                  5       0  100.00%
R/FilterStatesMAE.R                10       1  90.00%   40
R/FilterStatesMatrix.R              7       0  100.00%
R/FilterStatesSE.R                171      47  72.51%   36, 73-75, 85-87, 119, 191-201, 213-223, 230-237, 245-252, 259
R/include_css_js.R                  5       0  100.00%
R/teal_slice.R                    108       1  99.07%   206
R/teal_slices.R                    88       5  94.32%   152-157
R/test_utils.R                     21       0  100.00%
R/utils.R                          29       0  100.00%
R/variable_types.R                 15       1  93.33%   48
R/zzz.R                            16      16  0.00%    3-46
TOTAL                            4362     849  80.54%

Diff against main

Filename                  Stmts    Miss  Cover
----------------------  -------  ------  -------
R/FilterStateChoices.R       +5       0  +0.04%
TOTAL                        +5       0  +0.02%

Results for commit: 1ef290d

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 23, 2026

Unit Tests Summary

  1 files   31 suites   39s ⏱️
427 tests 412 ✅ 15 💤 0 ❌
896 runs  881 ✅ 15 💤 0 ❌

Results for commit 1ef290d.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 23, 2026

Unit Test Performance Difference

Test Suite $Status$ Time on main $±Time$ $±Tests$ $±Skipped$ $±Failures$ $±Errors$
FilteredData 💔 $19.37$ $+2.27$ $0$ $0$ $0$ $0$
Additional test case details
Test Suite $Status$ Time on main $±Time$ Test Case
ChoicesFilterState 👶 $+0.04$ Character_variable_with_label_attribute_displays_label_in_UI
ChoicesFilterState 👶 $+0.05$ Factor_with_label_attribute_displays_label_in_UI
ChoicesFilterState 👶 $+0.04$ Factor_with_same_label_as_varname_has_empty_varlabel_in_UI
ChoicesFilterState 👶 $+0.05$ Factor_without_label_attribute_has_empty_varlabel_in_UI
ChoicesFilterState 👶 $+0.04$ Numeric_variable_with_label_attribute_displays_label_in_UI

Results for commit 8bf1657

♻️ This comment has been updated with latest results.

@gogonzo gogonzo self-assigned this Feb 23, 2026
@osenan osenan requested a review from gogonzo February 23, 2026 13:45
@osenan
Copy link
Copy Markdown
Contributor Author

osenan commented Feb 24, 2026

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

Copy link
Copy Markdown
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.

👍 Please apply the last comment

@osenan osenan enabled auto-merge (squash) February 25, 2026 06:20
@osenan osenan merged commit 0b7f1c9 into main Feb 25, 2026
28 of 29 checks passed
@osenan osenan deleted the missing_variable_label@main branch February 25, 2026 06:21
@github-actions github-actions bot locked and limited conversation to collaborators Feb 25, 2026
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