rstudio / shiny

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

Traceback is upside down #2574

Open hadley opened 5 years ago

hadley commented 5 years ago

Running this:

library(shiny)

f <- function(x) g(x)
g <- function(x) h(x)
h <- function(x) x * 2

ui <- fluidPage(
  selectInput("n", "N", 1:10),
  plotOutput("plot")
)
server <- function(input, output, session) {
  output$plot <- renderPlot({
    n <- f(input$n)
    plot(head(cars, n))
  })
}
shinyApp(ui, server)

Prints:

Warning: Error in *: non-numeric argument to binary operator
  173: g [~/.active-rstudio-document#4]
  172: f [~/.active-rstudio-document#3]
  171: renderPlot [~/.active-rstudio-document#13]
  169: func
  129: drawPlot
  115: <reactive:plotObj>
   99: drawReactive
   86: origRenderFunc
   85: output$plot
    5: runApp
    3: print.shiny.appobj
    1: source

I'd argue that this traceback is upside down, because it's easier to read "f calls g calls h" rather than "h is called by g is called by f", and I think there's some evidence that R users find the other direction easier to understand (and it's the direction we've standardised on in r-lib/tidyverse).

hadley commented 5 years ago

Also note that the actual location of the error (h()) appears to be missing from the call stack.