Announcement: Stack traces!

868 views
Skip to first unread message

Joe Cheng [RStudio]

unread,
Nov 23, 2015, 2:03:24 PM11/23/15
to Shiny - Web Framework for R
We've made a simple but significant improvement to error handling in Shiny 0.12.2.9006. Errors now have stack traces!

Adding stack traces touched a fair amount of low-level code in Shiny, so I'd greatly appreciate it if you could upgrade to the development version (devtools::install_github("rstudio/shiny")) and let me know if you see any problems. We're hoping to release to CRAN in the coming weeks.

Consider this buggy app.R file:

 1: library(shiny)
 2: library(ggplot2)
 3: 
 4: ui <- fluidPage(
 5:   plotOutput("plot")
 6: )
 7: 
 8: server <- function(input, output, session) {
 9:   mydata <- reactive({
10:     head(25, cars)
11:   })
12:   
13:   output$plot <- renderPlot({
14:     ggplot(mydata(), aes(speed, dist)) + geom_point()
15:   })
16: }
17: 
18: shinyApp(ui, server)

Using the latest CRAN version of Shiny, running this app gives you output like this:

> shinyApp(ui, server)

Error : length(n) == 1L is not TRUE

And that's it--no clue where the error originated.

After installing the latest development version of Shiny the output becomes:

Warning: Error in : length(n) == 1L is not TRUE
Stack trace (innermost first):
    96: stopifnot
    95: head.default
    94: head
    93: reactive mydata [~/app.R#10]
    82: mydata
    81: ggplot
    80: renderPlot [~/app.R#14]
    72: output$plot
     5: <Anonymous>
     4: do.call
     3: print.shiny.appobj
     2: print
     1: source

The stack trace can be read from the bottom up: source() called print(), which called print.shiny.appobj(), which called do.call(), etc.

Generally you'll want to scan from the top down and find the first (i.e. innermost, i.e. most recent) call that comes from your project files--in this case, frame 93 implicates line 10 of app.R, which has "head(25, cars)". Ah, we've reversed the order of the arguments, it should've been "head(cars, 25)".

Notice that the numbers in the stack trace above aren't contiguous; it's missing entries for 6-71, 73-79, and 83-92. Shiny has a lot of internal plumbing, most of which is just not that interesting when you're trying to debug a problem in your app, so we try to hide uninteresting parts of the stack trace. If you suspect that useful information is being hidden, you can turn off the hiding with this option:

options(shiny.fullstacktrace = TRUE)

Hope you find this change useful!

-joe

Dean Attali

unread,
Nov 23, 2015, 7:18:15 PM11/23/15
to Shiny - Web Framework for R
This sounds great, thanks for this much needed feature! I'll report if I see any problems

Dean Attali

unread,
Nov 23, 2015, 7:46:58 PM11/23/15
to Shiny - Web Framework for R
I just tried using the dev shiny version of some simple apps I have and I seem to be getting problems with one of them.  I put the code of the app in a gist https://gist.github.com/daattali/d7d72d37229e072f9376
If I run the app using Run App button or using the runApp function, then it works. If I run the app in any way using the CRAN version, then it works. But using the new version, if I manually copy and paste all the lines of the app into the console and run them, this is the output

ERROR: [on_request_read] connection reset by peer
Warning: Error in if: missing value where TRUE/FALSE needed
Stack trace (innermost first):
    45: srcrefToLabel
    44: reactive
    43: server [#38]
     4: <Anonymous>
     3: do.call
     2: print.shiny.appobj
     1: print
Error in if (m[[1]][1] == -1) { : missing value where TRUE/FALSE needed
Warning: Error in nrow: could not find function "prices"
Stack trace (innermost first):
    73: nrow
    72: renderText [#31]
    71: func
    70: output$summaryText
     4: <Anonymous>
     3: do.call
     2: print.shiny.appobj
     1: print
ERROR: [on_request_read] connection reset by peer


The second error seems to be because I'm using a reactive value before it is being defined, so by moving the  `prices <- reactive({...})` statement to the top, it gets fixed, though that was never an issue previously.
The first error is something with `srcrefToLabel` which I'm not familiar with.

Sorry for not giving a minimal reproduceable example, I'm fairly busy but wanted to quickly check it out and not spent too much time on debugging myself, hopefully this is useful


 
On Monday, 23 November 2015 11:03:24 UTC-8, Joe Cheng [RStudio] wrote:

Joe Cheng

unread,
Nov 23, 2015, 8:03:00 PM11/23/15
to Dean Attali, Shiny - Web Framework for R
Thanks for the quick feedback and repro! That gist is plenty minimal for me. :)

Can you also send me the output of sessionInfo()? I'm seeing the problem on my side too (I have to admit I didn't test with pasting apps right into the console) but with a different set of error messages, just want to make sure I don't miss an edge case.

Thanks!

--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/826ca1fe-b7dc-4a81-81ba-bb0bc07d2204%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dean Attali

unread,
Nov 23, 2015, 8:30:42 PM11/23/15
to Shiny - Web Framework for R, daat...@gmail.com
I actually do get different errors on my two different machines, that are running different versions of R.

Machine 1:

R version 3.1.3 (2015-03-09)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=English_Canada.1252  LC_CTYPE=English_Canada.1252   
[3] LC_MONETARY=English_Canada.1252 LC_NUMERIC=C                   
[5] LC_TIME=English_Canada.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] tools_3.1.3

Warning: Error in if: missing value where TRUE/FALSE needed
Stack trace (innermost first):
    45: srcrefToLabel
    44: reactive
    43: server [#30]
     4: <Anonymous>
     3: do.call
     2: print.shiny.appobj
     1: print
Error in if (m[[1]][1] == -1) { : missing value where TRUE/FALSE needed
ERROR: [on_request_read] connection reset by peer


Machine 2:

R version 3.2.2 (2015-08-14)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=English_Canada.1252  LC_CTYPE=English_Canada.1252   
[3] LC_MONETARY=English_Canada.1252 LC_NUMERIC=C                   
[5] LC_TIME=English_Canada.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] tools_3.2.2

Warning: Error in if: missing value where TRUE/FALSE needed
Warning in value[[3L]](cond) :
  Failed to write stack trace: Error in as.character(call[[1]]): cannot coerce type 'promise' to vector of type 'character'

Error in if (m[[1]][1] == -1) { : missing value where TRUE/FALSE needed
Warning: Error in nrow: could not find function "prices"
Warning in value[[3L]](cond) :
  Failed to write stack trace: Error in as.character(call[[1]]): cannot coerce type 'promise' to vector of type 'character'

Joe Cheng

unread,
Nov 24, 2015, 2:55:50 PM11/24/15
to Dean Attali, Shiny - Web Framework for R
I think I fixed both issues--can you give it another try? Thanks.

Dean Attali

unread,
Nov 24, 2015, 3:47:02 PM11/24/15
to Shiny - Web Framework for R, daat...@gmail.com
It does work now , on both machines, thank you.  However, now running `shinyApp()` launches the browser by default instead of using the Viewer panel. I don't think this was the case yesterday, or maybe I didn't notice.

I'll continue using and report if I run into any more issues

Joe Cheng

unread,
Nov 24, 2015, 5:11:28 PM11/24/15
to Dean Attali, Shiny - Web Framework for R
That's weird. Can you try installing the CRAN version and let me know if this is indeed a regression?

Dean Attali

unread,
Nov 30, 2015, 2:36:15 AM11/30/15
to Shiny - Web Framework for R, daat...@gmail.com
I thought I replied to this, but I don't see my reply. Yes, this IS a regression, I used to always be able to view my apps in the Viewer panel by default

Joe Cheng

unread,
Nov 30, 2015, 2:46:41 AM11/30/15
to Dean Attali, Shiny - Web Framework for R
Strange, I'm not reproing on R 3.2.2, RStudio 0.99.780.

Can you confirm that your repro steps are 1) ensure "Run in Viewer Pane" is selected in the Run App dropdown, and 2) click Run App?

Screen Shot 2015-11-29 at 11.44.36 PM.png

satheesh kantam

unread,
Dec 17, 2015, 1:55:18 AM12/17/15
to Shiny - Web Framework for R
Dear Concern,

I have question on Shiny not related to below chain mail. What is the latest version of Rstudio, which can support all latest packages.

I have ran simple shiny app, I'm not getting the output. I'm getting different errors, please let me know how can use shiny.

what all are the packages required to run Shiny app.

Your quick response is much appreciated.

Thank you in advance.

one of the error as below:

Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) : 
  there is no package called ‘mime’
In addition: Warning message:
package ‘shiny’ was built under R version 3.0.3 
Error: package or namespace load failed for ‘shiny’

ui.r

library(shiny)
# Define UI for application that draws a histogram
shinyUI(fluidPage(
 
  # Application title
  titlePanel("Hello Shiny!"),
 
  # Sidebar with a slider input for the number of bins
  sidebarLayout(
    sidebarPanel(
      sliderInput("bins",
                  "Number of bins:",
                  min = 1,
                  max = 50,
                  value = 30)
    ),
   
    # Show a plot of the generated distribution
    mainPanel(
      plotOutput("distPlot")
    )
  )
))

server.r
library(shiny)
# Define server logic required to draw a histogram
shinyServer(function(input, output) {
 
  # Expression that generates a histogram. The expression is
  # wrapped in a call to renderPlot to indicate that:
  #
  #  1) It is "reactive" and therefore should be automatically
  #     re-executed when inputs change
  #  2) Its output type is a plot
 
  output$distPlot <- renderPlot({
    x    <- faithful[, 2]  # Old Faithful Geyser data
    bins <- seq(min(x), max(x), length.out = input$bins + 1)
   
    # draw the histogram with the specified number of bins
    hist(x, breaks = bins, col = 'darkgray', border = 'white')
  })
 
})

Thank you
Satheesh K

Deville Deville

unread,
Dec 28, 2015, 8:01:38 AM12/28/15
to Shiny - Web Framework for R
 Greetings!!!!

    Dear Concern,
   
    Please, I would like to know how to create a cluster of  three shiny servers?
    The idea is that i would like an application deployed on a server to still be accessible in case of failure of that server from another one.
    Any suggestions to solve  will be a great pleasure. 

Thank you for responding.

Deville

Joe Cheng

unread,
Dec 28, 2015, 3:49:23 PM12/28/15
to Deville Deville, Shiny - Web Framework for R
You should set up a separate load balancer in front of three shiny servers. You can do this for free using nginx or HAProxy; both are used by huge sites to do load balancing, and they both have extensive options for failover policies.

--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.

Deville Deville

unread,
Dec 29, 2015, 6:12:30 AM12/29/15
to Shiny - Web Framework for R
Hello Joe,

Thank you for responding.

I have another question. Before i should find the availability of a server using the loadBalancer, there must be a communication amongst the shiny server. Then, my question now is to know how to make two or three shiny servers communicate to each other?

Thanks in advance.


On Monday, November 23, 2015 at 8:03:24 PM UTC+1, Joe Cheng [RStudio] wrote:

Joe Cheng

unread,
Dec 29, 2015, 12:28:12 PM12/29/15
to Deville Deville, Shiny - Web Framework for R
(Changing subject to get off the stack traces announcement thread)

What communication do you need between the shiny servers? Normally when you load balance web applications you create multiple identical but independent servers that you then put behind a load balancer. Each (shiny) server doesn't need to know that the others exist.

--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.

Jian Wang

unread,
Jan 4, 2016, 4:55:01 PM1/4/16
to Shiny - Web Framework for R
Hi Joe, This is a great feature.  Just curious, why is that my output slightly different from yours.  Specifically not gives the code line number which I think is very useful.
Warning: Error in : length(n) == 1L is not TRUE
Stack trace (innermost first):
    95: stopifnot
    94: head.default
    93: head
    92: reactive mydata [#3]
    81: mydata
    80: ggplot
    79: renderPlot [#7]
    71: output$plot
     4: <Anonymous>
     3: do.call
     2: print.shiny.appobj
     1: print

> sessionInfo()
R version 3.2.0 (2015-04-16)
Platform: x86_64-unknown-linux-gnu (64-bit)
Running under: Red Hat Enterprise Linux Server release 6.6 (Santiago)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ggplot2_1.0.1     shiny_0.12.2.9006

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.1      digest_0.6.8     MASS_7.3-42      mime_0.4         grid_3.2.0       R6_2.1.1         plyr_1.8.3      
 [8] jsonlite_0.9.19  xtable_1.8-0     gtable_0.1.2     magrittr_1.5     scales_0.3.0     stringi_1.0-1    reshape2_1.4.1  
[15] proto_0.3-10     Cairo_1.5-8      tools_3.2.0      stringr_1.0.0    munsell_0.4.2    httpuv_1.3.3     colorspace_1.2-6
[22] htmltools_0.2.6 

Joe Cheng

unread,
Jan 4, 2016, 5:26:24 PM1/4/16
to Jian Wang, Shiny - Web Framework for R
I'm not sure. Can you try doing shiny::runApp on the app directory, instead of printing the shiny app obj?
--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.

Max Moro

unread,
Jan 5, 2016, 10:28:29 AM1/5/16
to Shiny - Web Framework for R
Hi Joe,
I loaded an issue on GITHUB (#1042) where the following code is not working with the DEVL version of shiny.
Basically, if I remove the dataRange input or the options parameter in the Selectize, it works.
Can you test the code below?
Thanks!



library(shiny)
library(shinydashboard)
shinyApp(
    ui = dashboardPage(title='Time Application'
                       #header
                       ,dashboardHeader(title=strong(h4("Time Application")),titleWidth='150px')
                       #left side tabs
                       ,dashboardSidebar(
                           sidebarMenu(id='tabs',menuItem("Filters",icon=icon("filter"), tabName='tab_parameters')) 
                           ,width='150px'
                       )
                       #body of the application, based on the tab
                       ,dashboardBody(
                           tabItems(
                               tabItem(tabName = 'tab_parameters'
                                       ,fluidRow(
                                           box(width=6,title='Filters'
                                               #remove dateRange input and  it works
                                               ,dateRangeInput("period"
                                                               , label ="Period"
                                                               , min  = '2013-01-01'
                                                               , max  = '2016-01-01'
                                                               , start = '2013-01-01'
                                                               , end = '2016-01-01'
                                               )
                                           )
                                       )
                                       ,fluidRow(width=12,box(status='success',title='Group By' 
                                                              ,selectizeInput( "OT_summary_criteria"
                                                                               , label =NULL
                                                                               , multiple=TRUE
                                                                               , choices = c('a','b')
                                                                               , selected ='a'
                                                                               #remove next line and it works
                                                                               , options=list(plugins = list('remove_button','drag_drop'))
                                                              )
                                       ))
                                       ,"You should see something here below if it works:"
                                       ,textOutput('infot')
                               )
                           )
                       )
    )
    ,
    server =
        function(input, output, session) {
            output$infot = renderText( paste0('IT IS WORKING'))
        }
)


Max Moro

unread,
Jan 5, 2016, 12:20:04 PM1/5/16
to Shiny - Web Framework for R
Ok, this is fixed. Winston updated Shiny.

Thank you!
Max

Jian Wang

unread,
Jan 18, 2016, 3:25:47 PM1/18/16
to Shiny - Web Framework for R
Hi Dean:  Do you have plan to update your shinyjs to work with shiny modules? Thanks,  -Jian

Dean Attali

unread,
Jan 18, 2016, 3:36:16 PM1/18/16
to Shiny - Web Framework for R
Jian: I did that over the weekend. If you download the GitHub version of shinyjs, it should work with modules. If you find a problem please file a bug report

Jian Wang

unread,
Jan 18, 2016, 8:22:58 PM1/18/16
to Shiny - Web Framework for R
Hi Dean:  Using module approach, I tested to enable and disable actionButton based on if selectInput value is selected.  still not working.  I will go ahead to file a bug report.  Thanks much.

Jian Wang

unread,
Jan 21, 2016, 10:57:07 AM1/21/16
to Shiny - Web Framework for R
Just to close the loop here.  All is working fine.  It is actually my fault to put ns() unnecessarily.  -Jian
Reply all
Reply to author
Forward
0 new messages