insightsengineering / insightsengineering/teal.widgets
[Bug]: Download button doesn't receive the file_name
- Dominant language
- R
- Stars
- 6
- Forks
- 8
- PR merge metrics
- No merged PRs in 30d
Description
### What happened?
On the [CI one test is failing](https://github.com/insightsengineering/teal.widgets/actions/runs/34450207450/job/102783988666)
```
[ FAIL 1 | WARN 0 | SKIP 0 | PASS 423 ]
══ Failed tests ════════════════════════════════════════════════════════════════
── Error ('test-table_with_settings.R:289:9'): type_download_srv_table: downloading gtsummary output types ──
Error in `gt::gtsave(x, filename = file)`: A file extension is required in the provided filename.
i We can use:
* `.html`, `.htm` (HTML file)
* `.png` (PNG file)
* `.pdf` (PDF file)
* `.tex`, `.rnw` (LaTeX file)
* `.rtf` (RTF file)
* `.docx` (Word file)
```
The tests is modified on #362 to make it pass by explicitly passing a file_name as input. The test failing is this one:
```r
testthat::test_that("type_download_srv_table: downloading gtsummary output types", {
tbl_split_r <- shiny::reactive({
gtsummary::tbl_summary(gtsummary::trial, by = "trt")
})
shiny::testServer(
teal.widgets:::type_download_srv_table,
args = list(id = "tws", table_reactive = tbl_split_r),
expr = {
for (down_type in c(".txt", ".csv", ".pdf")) {
if (down_type == ".pdf") {
testthat::skip_if_not_installed("webshot2")
testthat::skip_on_cran()
}
session$setInputs(
"pagination_switch" = FALSE,
"file_format" = down_type
)
testthat::expect_true(file.exists(output$data_download))
testthat::expect_equal(
basename(output$data_download), paste0(input$file_name, down_type)
)
}
}
)
})
```
The problem is that the download is not getting the input$file_name and `gtsave()` receives only as filename ".pdf" that is not accepted.
It is not clear why the `input$file_name` is missing despite the `textInput(ns("file_name"), value =)` default.
### sessionInfo()
```R
```
### Relevant log output
```R
[ FAIL 1 | WARN 0 | SKIP 0 | PASS 423 ]
══ Failed tests ════════════════════════════════════════════════════════════════
── Error ('test-table_with_settings.R:289:9'): type_download_srv_table: downloading gtsummary output types ──
Error in `gt::gtsave(x, filename = file)`: A file extension is required in the provided filename.
i We can use:
* `.html`, `.htm` (HTML file)
* `.png` (PNG file)
* `.pdf` (PDF file)
* `.tex`, `.rnw` (LaTeX file)
* `.rtf` (RTF file)
* `.docx` (Word file)
Backtrace:
▆
1. ├─shiny::testServer(...) at test-table_with_settings.R:276:3
2. │ ├─shiny:::withMockContext(...)
3. │ │ ├─shiny::isolate(...)
4. │ │ │ ├─shiny::..stacktraceoff..(...)
5. │ │ │ └─ctx$run(...)
6. │ │ │ ├─promises::with_promise_domain(...)
7. │ │ │ │ └─domain$wrapSync(expr)
8. │ │ │ ├─shiny::withReactiveDomain(...)
9. │ │ │ │ └─promises::with_promise_domain(...)
10. │ │ │ │ └─domain$wrapSync(expr)
11. │ │ │ │ └─base::force(expr)
12. │ │ │ ├─shiny:::with_otel_span_context(...)
13. │ │ │ │ └─base::force(expr)
14. │ │ │ ├─shiny::captureStackTraces(...)
15. │ │ │ │ └─promises::with_promise_domain(...)
16. │ │ │ │ └─domain$wrapSync(expr)
17. │ │ │ │ └─base::withCallingHandlers(expr, error = doCaptureStack)
18. │ │ │ └─env$runWith(self, func)
19. │ │ │ └─shiny (local) contextFunc()
20. │ │ │ └─shiny::..stacktraceon..(expr)
21. │ │ ├─shiny::withReactiveDomain(...)
22. │ │ │ └─promises::with_promise_domain(...)
23. │ │ │ └─domain$wrapSync(expr)
24. │ │ │ └─base::force(expr)
25. │ │ └─withr::with_options(...)
26. │ │ └─base::force(code)
27. │ └─rlang::eval_tidy(quosure, mask, rlang::caller_env())
28. ├─testthat::expect_true(file.exists(output$data_download)) at test-table_with_settings.R:289:9
29. │ └─testthat::quasi_label(enquo(object), label)
30. │ └─rlang::eval_bare(expr, quo_get_env(quo))
31. ├─base::file.exists(output$data_download)
32. ├─output$data_download
33. └─shiny:::`$.shinyoutput`(output, data_download)
34. └─.subset2(x, "impl")$getOutput(name)
35. └─private$renderFile(self$ns(name), download)
36. └─download$content(file)
37. ├─teal.widgets:::export_table(...)
38. └─teal.widgets:::export_table.gtsummary(...)
39. ├─teal.widgets:::export_table(...)
40. └─teal.widgets:::export_table.gt_tbl(...)
41. └─gt::gtsave(x, filename = file)
42. └─cli::cli_abort(...)
43. └─rlang::abort(...)
[ FAIL 1 | WARN 0 | SKIP 0 | PASS 423 ]
```
### Code of Conduct
- [x] I agree to follow this project's Code of Conduct.
### Contribution Guidelines
- [x] I agree to follow this project's Contribution Guidelines.
### Security Policy
- [x] I agree to follow this project's Security Policy.
Contributor guide
Research direction
Start with test-table_with_settings.R and the type_download_srv_table entry point, reproducing the gtsummary download failure shown in the test. Trace how input$file_name reaches export_table.gtsummary and gt::gtsave(). Done means the download has the expected filename with its selected extension and the focused test passes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- backend, testing
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 74/100