Skip to content

[Bug]: Download button doesn't receive the file_name #363

Description

@llrs-roche

What happened?

On the CI one test is failing

  [ 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:

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()

Relevant log output

[ 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

  • I agree to follow this project's Code of Conduct.

Contribution Guidelines

  • I agree to follow this project's Contribution Guidelines.

Security Policy

  • I agree to follow this project's Security Policy.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions