Skip to content

[Feature Request]: table_with_settings_srv accepts NULL #344

@averissimo

Description

@averissimo

Feature description

In tm_a_mmrm the logic passes NULL to table_with_settings_srv and plot_with_settings_srv, which fails on the latter and shows an error in the console.

Suggestion is to handle it correctly and (possibly) show a placeholder text showing "no table/image provided"

This should never appear in a module, but I think it's fair for the functions to accept it

Example app (with NULL added)

pkgload::load_all("../teal.widgets")
ui <- bslib::page_fluid(
  table_with_settings_ui(id = "null_table"),
  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 = "null_table", table_r = reactive(NULL))
  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)
}

shinyApp(ui, server) |> shiny::runApp()
#> ℹ Loading teal.widgets
#> 
#> Listening on http://127.0.0.1:7380
#> Warning: Error in render_table_to_html.default: Unsupported table type. table_with_settings supports rtables (ElementaryTable, TableTree), gtsummary, or gt (gt_tbl) objects.
#>   119: stop
#>   118: render_table_to_html.default [/path/to/teal.widgets/R/table_with_settings.R#32]
#>   116: renderUI [/path/to/teal.widgets/R/table_with_settings.R#274]
#>   115: func
#>    99: output$null_table-table_out_main
#>     1: shiny::runApp
Metadata

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.

Metadata

Metadata

Assignees

No one assigned
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions