Skip to content

Conversation

@m7pr
Copy link
Contributor

@m7pr m7pr commented Jan 29, 2026

Fix

Idea, we extract export_table and render_table_to_html out of the existing functionality for rtables and we add a dispatch for gt_tbl and gtsummary objects :)

Tested with
library(shiny)
library(rtables)
library(gtsummary)
library(gt)
library(magrittr)

ui <- bslib::page_fluid(
  table_with_settings_ui(id = "rtables_table"),
  table_with_settings_ui(id = "gtsummary_table"),
  table_with_settings_ui(id = "gt_table")
)

server <- function(input, output, session) {
  table_r_rtables <- reactive({
    l <- basic_table() %>%
      split_cols_by("ARM") %>%
      analyze(c("SEX", "AGE"))
    build_table(l, DM)
  })

  table_r_gtsummary <- reactive({
    gtsummary::tbl_summary(mtcars)
  })

  table_r_gt <- reactive({
    mtcars %>%
      gt::gt() %>%
      gt::tab_header(title = "Motor Trend Car Road Tests")
  })

  table_with_settings_srv(id = "rtables_table", table_r = table_r_rtables)
  table_with_settings_srv(id = "gtsummary_table", table_r = table_r_gtsummary)
  table_with_settings_srv(id = "gt_table", table_r = table_r_gt)
}

if (interactive()) {
  shinyApp(ui, server)
}

gtsummary

image

PDF export

image

CSV export

image

TEXT export

image

gt

image

PDF export

image

CSV export

image

TEXT export

image

@m7pr m7pr added the core label Jan 29, 2026
@m7pr
Copy link
Contributor Author

m7pr commented Jan 29, 2026

Hey @llrs-roche and @gogonzo
Before going further, just wanted to consult the idea of implementing support for gt and gtsummary inside table_with_settings.

I though we can dispatch the current approach implement for rtables, to support gt and gtsummary objects. For now there are placeholder. What do you think? If you give it a green light, I'll try to fill placeholders with actual implementation

@llrs-roche
Copy link
Contributor

I think using dispatch is the best approach. This way we can support new objects like on #334
The class, file, format abstraction should work well in my opinion 👍

@gogonzo
Copy link
Contributor

gogonzo commented Jan 29, 2026

Looks very good ⭐

@github-actions
Copy link
Contributor

github-actions bot commented Jan 29, 2026

badge

Code Coverage Summary

Filename                      Stmts    Miss  Cover    Missing
--------------------------  -------  ------  -------  ------------------------------------------------------
R/basic_table_args.R             23       0  100.00%
R/draggable_buckets.R            87      12  86.21%   116-121, 151-156
R/get_dt_rows.R                  13       0  100.00%
R/ggplot2_args.R                 49       0  100.00%
R/nested_closeable_modal.R       20      20  0.00%    83-103
R/optionalInput.R               255      79  69.02%   190, 315-389, 402-409, 411-416, 434, 436, 501, 583-596
R/panel_group.R                  39      39  0.00%    50-136
R/plot_with_settings.R          309      16  94.82%   299-305, 327, 364, 373-374, 390, 578-579, 581, 583
R/standard_layout.R              52       4  92.31%   90-93
R/table_with_settings.R         199      24  87.94%   32-36, 82, 127-158
R/utils.R                         7       0  100.00%
R/verbatim_popup.R              105      35  66.67%   113-114, 116, 124-155
R/white_small_well.R              7       0  100.00%
TOTAL                          1165     229  80.34%

Diff against main

Filename                   Stmts    Miss  Cover
-----------------------  -------  ------  -------
R/table_with_settings.R      +41     +23  -11.43%
TOTAL                        +41     +23  -1.33%

Results for commit: c011502

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

@github-actions
Copy link
Contributor

github-actions bot commented Jan 29, 2026

Unit Tests Summary

  1 files   16 suites   1m 51s ⏱️
172 tests 172 ✅ 0 💤 0 ❌
399 runs  399 ✅ 0 💤 0 ❌

Results for commit c011502.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 29, 2026

Unit Test Performance Difference

Test Suite $Status$ Time on main $±Time$ $±Tests$ $±Skipped$ $±Failures$ $±Errors$
plot_with_settings_ui 💚 $52.45$ $-3.04$ $0$ $0$ $0$ $0$
table_with_settings 💔 $2.20$ $+1.20$ $+7$ $0$ $0$ $0$
table_with_settings_ui 💚 $33.12$ $-1.27$ $0$ $0$ $0$ $0$
Additional test case details
Test Suite $Status$ Time on main $±Time$ Test Case
table_with_settings 👶 $+0.19$ table_with_settings_srv_gt_table_renders_with_content
table_with_settings 👶 $+1.26$ table_with_settings_srv_gtsummary_table_renders_with_content
table_with_settings 💀 $0.12$ $-0.12$ table_with_settings_srv_return_html_table
table_with_settings 👶 $+0.10$ table_with_settings_srv_return_html_table_with_content

Results for commit c0c18fc

♻️ This comment has been updated with latest results.

@m7pr
Copy link
Contributor Author

m7pr commented Jan 29, 2026

Amazing, I will proceed with implementation, some examples and finally with tests

@m7pr m7pr changed the title WIP skeleton for gtsummary support in table_with_settings [WIP] gtsummary support in table_with_settings Jan 30, 2026
github-actions bot and others added 3 commits January 30, 2026 15:10
Signed-off-by: Marcin <133694481+m7pr@users.noreply.github.com>
Signed-off-by: Marcin <133694481+m7pr@users.noreply.github.com>
Copy link
Contributor

@llrs-roche llrs-roche left a comment

Choose a reason for hiding this comment

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

Looks almost ready.

For the text format of gtsummary could we use like a table with write.table() but without quotes? It will be easier to read than the html as it includes many tags, attrigutes and some elements that are out of the table:

<div id="uftobyoadg" style="padding-left:0px;padding-right:0px;padding-top:10px;padding-bottom:10px;overflow-x:auto;overflow-y:auto;width:auto;height:auto;">

But I'm not really sure who will use the text format of gtsummary. If this is for reporting it won't look good.

Not sure what I missed but the tests don't seem to cover anything from the file (but at the same time the CI only reports a 1% decrease)

covr::file_coverage("R/table_with_settings.R", "tests/testthat/test-table_with_settings.R")
Test passed with 2 successes 🥳.
Test passed with 1 success 🥇.
Test passed with 3 successes 😸.
Test passed with 1 success 😸.
Test passed with 6 successes 😀.
Test passed with 6 successes 🎉.
Test passed with 6 successes 🥳.
Test passed with 2 successes 🌈.
Test passed with 1 success 🌈.
Test passed with 1 success 🎊.
Test passed with 3 successes 🥳.
Test passed with 3 successes 🥳.
Coverage: 0.00%
R/table_with_settings.R: 0.00%

@llrs-roche llrs-roche self-assigned this Feb 2, 2026
@m7pr
Copy link
Contributor Author

m7pr commented Feb 3, 2026

Hey @llrs-roche I applied your feedback.

  • TEXT export looks better now (I updated print-screens in the initial PR descripion).
  • The example was also updated, and now it shows the difference of 3 different supported objects in one shiny app.
  • Also adjusted and simplified implementation

If you accept I will try to remove formatters and rtables from Remotes, before I merge

Copy link
Contributor

@llrs-roche llrs-roche left a comment

Choose a reason for hiding this comment

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

gt text export should not print the X1, X2, X3 if possible other than that I am a bit unsure about all the methods and how they are used. But let's merge it.

Remember to test without the dev versions of rtables and formatters and to fix the style and lintr checks.

One last question. Is it possible to test the file downloaded/generated? I'm just wondering if we can test that it produces something without writing to the temp folder

@m7pr
Copy link
Contributor Author

m7pr commented Feb 3, 2026

@llrs-roche I was able to cleanup gt objects, so the title of the table is dropped and we only save the data in text output

image

@m7pr
Copy link
Contributor Author

m7pr commented Feb 3, 2026

Remember to test without the dev versions of rtables and formatters and to fix the style and lintr checks.

Will test now!

One last question. Is it possible to test the file downloaded/generated? I'm just wondering if we can test that it produces something without writing to the temp folder

No idea. I think we should be able to test the content of the file that is saved to temp folder.
Without writing we are testing the content of the object in table_with_settings_srv testServer tests.

We've got this

testthat::test_that("table_with_settings_srv: gt table renders with content", {
  gt_r <- shiny::reactive({
    gt::gt(mtcars[1:5, 1:3])
  })

  shiny::testServer(
    teal.widgets::table_with_settings_srv,
    args = list(id = "tws", table_r = gt_r),
    expr = {
      html_content <- as.character(output$table_out_main$html)
      testthat::expect_s3_class(output$table_out_main$html, "html")
      testthat::expect_true(grepl("mpg|cyl|disp", html_content, ignore.case = TRUE))
      testthat::expect_true(grepl("<table", html_content, ignore.case = TRUE))
    }
  )
})

@m7pr m7pr enabled auto-merge (squash) February 3, 2026 15:30
@m7pr m7pr changed the title [WIP] gtsummary support in table_with_settings gtsummary support in table_with_settings Feb 3, 2026
@m7pr m7pr merged commit f1ccb07 into main Feb 3, 2026
57 of 59 checks passed
@m7pr m7pr deleted the gtsummary_support branch February 3, 2026 16:30
@github-actions github-actions bot locked and limited conversation to collaborators Feb 3, 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.

3 participants