rstudio / shiny

Easy interactive web applications with R
https://shiny.posit.co/
Other
5.37k stars 1.86k forks source link

Need easier way to debug #1495

Open renkun-ken opened 7 years ago

renkun-ken commented 7 years ago

I'm using shiny and shinydashboard which periodically query a mongodb server and present data in the dashboard. The dashboard is highly dynamic since its menu and tab pages are dynamically determined by the config and database entries. The dashboard also uses reactive variables to ensure the data are the latest.

Recently I rewrote a major part of the dashboard and it is broken with an stack trace that cannot be more simplified:

Listening on http://0.0.0.0:8080
Warning: Error in if: argument is of length zero
Stack trace (innermost first):
    4: <Anonymous>
    3: do.call
    2: print.shiny.appobj
    1: <Promise>
Error : argument is of length zero

If any line number is provided in the stack trace, it would be much better than having no clue at all.

bborgesr commented 7 years ago

Can you give us a minimal reproducible example?

jcheng5 commented 7 years ago

Try options(shiny.fullstacktrace=TRUE) before running the app and let us know if you get a bigger stack trace.

renkun-ken commented 7 years ago

I notice that if the error is in the server function, the stack trace is helpful enough to find the errors. Unfortunately, I found that the error was actually in body which seems to be lazily evaluated till shinyApp is called. In this case, if I do not force evaluating body, it will be harder to find where the problem is.

The following is a simple example to reproduce this:

library(shiny)
library(shinydashboard)

header <- dashboardHeader(title = "Dashboard")

config <- list()

sidebar <- dashboardSidebar(
  sidebarMenu(
    menuItem("Overview", tabName = "overview")
  )
)

body <- dashboardBody(tabItems(
  tabItem(tabName = "overview",
    tabBox(title = "Overview", width = "100%",
      tabPanel("Summary", tableOutput(sprintf("table-%s", config$title)))
))))

ui <- dashboardPage(header, sidebar, body)

server <- function(input, output, session) {
  output[[sprintf("table-%s", config$title)]] <- renderTable(mtcars)
}

shinyApp(ui, server)

Above, config$title is exceptionally NULL but from the error message or stack trace I cannot quickly find it, not until I evaluate body and see the error:

> body
Error in if (!is.na(attribValue)) { : argument is of length zero
nawarhalabi commented 4 years ago

By using options(shiny.fullstacktrace=TRUE) I get a deeper stacktrace but still I do not see the line number of the errors.