Trace UI warning in shiny

,

Here a SO crosspost can be found.

The below shiny app will raise the following warning:

Warning: Navigation containers expect a collection of `bslib::nav_panel()`/`shiny::tabPanel()`s and/or `bslib::nav_menu()`/`shiny::navbarMenu()`s. Consider using `header` or `footer` if you wish to place content above (or below) every panel's contents.

The reason for this warning is clear.

I'm wondering if there is a way to trace the origin (a linenumber) of this warning.

The usecase is a much bigger app calling shinydashboard::tabBox several times.

I tried using devmode and different debugging options in RStudio, but so far without a viable reference.


library(shiny)

devmode()
options(warn = 2, shiny.error = browser, shiny.fullstacktrace = TRUE, shiny.trace = TRUE)

ui <- function(request){
  fluidPage(
    tabsetPanel(
      div("This will raise a warning. What is my linenumber?")
    )
  )
}

server <- function(input, output, session) {}

shinyApp(ui, server)

I got another answer by @gadenbuie here, with which I was able to find the source of the warning:

If ui is a function, you can call ui() directly, which, along with warn = 2 and the other options you have set, should surface a usable stack trace.

library(shiny)

options(warn = 2, error = rlang::entrace)

ui <- function(request){
  fluidPage(
    tabsetPanel(
      div("This will raise a warning. What is my linenumber?")
    )
  )
}

ui()
#> Error:
#> ! (converted from warning) Navigation containers expect a collection of `bslib::nav_panel()`/`shiny::tabPanel()`s and/or `bslib::nav_menu()`/`shiny::navbarMenu()`s. Consider using `header` or `footer` if you wish to place content above (or below) every panel's contents.
rlang::last_trace()
#> <error/rlang_error>
#> Error:
#> ! (converted from warning) Navigation containers expect a collection of `bslib::nav_panel()`/`shiny::tabPanel()`s and/or `bslib::nav_menu()`/`shiny::navbarMenu()`s. Consider using `header` or `footer` if you wish to place content above (or below) every panel's contents.
#> ---
#> Backtrace:
#>      ▆
#>   1. └─global ui()
#>   2.   ├─shiny::fluidPage(tabsetPanel(div("This will raise a warning. What is my linenumber?")))
#>   3.   │ ├─shiny::bootstrapPage(...)
#>   4.   │ │ └─rlang::list2(...)
#>   5.   │ └─htmltools::div(class = "container-fluid", ...)
#>   6.   │   └─rlang::dots_list(...)
#>   7.   └─shiny::tabsetPanel(div("This will raise a warning. What is my linenumber?"))
#>   8.     ├─shiny:::remove_first_class(...)
#>   9.     └─bslib (local) func(..., id = id, selected = selected, header = header, footer = footer)
#>  10.       └─bslib (local) new(...)
#>  11.         └─bslib:::tabsetPanel_(...)
#>  12.           └─bslib:::buildTabset(...)
#>  13.             └─base::lapply(...)
#>  14.               └─bslib (local) FUN(X[[i]], ...)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.