suppress red error messages in shiny webpage

18,519 views
Skip to first unread message

Willi Fiebranz

unread,
Apr 23, 2013, 11:24:44 AM4/23/13
to shiny-...@googlegroups.com
Hi,

I have a very big and dynamic shiny interface that build in several step.

However, while doing so often red error output from reactive functions occurs very shortly, before the intended output arrives.

I tried "options(show.error.messages = FALSE)" in all three relevant scripts (ui, server, and "run"), but it shows no effect.

Is there a way?


Joe Cheng

unread,
Apr 23, 2013, 12:30:22 PM4/23/13
to shiny-...@googlegroups.com
I recommend having your reactive functions/expressions and renderers check whether their dependencies are ready, and return NULL if not; this way, if you do have a real error later in the app, it will still be shown.

However, if you really want to hide error messages, you can do it with this CSS (add it anywhere in your page):

tags$style(type="text/css",
  ".shiny-output-error { visibility: hidden; }",
  ".shiny-output-error:before { visibility: hidden; }"
)




--
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.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Willi Fiebranz

unread,
Apr 24, 2013, 4:06:36 AM4/24/13
to shiny-...@googlegroups.com
Thanks,

but can you give me a small example of pseudo-code how to check if a input-dependency is ready?

Best,
WF

Mike C

unread,
Apr 24, 2013, 9:29:42 AM4/24/13
to shiny-...@googlegroups.com
if(is.null(input$somethingInThere))
return()

if(is.null(input$somethingElseInThere))
return()
Message has been deleted

Anitha Raman

unread,
Mar 28, 2014, 5:40:16 AM3/28/14
to shiny-...@googlegroups.com

Hi Joe,

 Looks like the code you have provided suits the HTML UI, however I am using Shiny UI. Can you please provide the pseudo code to mirror this action in UI.R?

Joe Cheng

unread,
Mar 28, 2014, 3:10:57 PM3/28/14
to Anitha Raman, shiny-...@googlegroups.com
Anitha, you should literally paste that code into your ui.R right into your mainPanel, just like it is another output or something. For example:

shinyUI(pageWithSidebar(
  headerPanel("Hi"),
  sidebarPanel(sliderInput(...)),
  mainPanel(
    tags$style(type="text/css",
      ".shiny-output-error { visibility: hidden; }",
      ".shiny-output-error:before { visibility: hidden; }"
    ),
    plotOutput("plot")
  )
))



For more options, visit https://groups.google.com/d/optout.

Anitha Raman

unread,
Apr 1, 2014, 5:55:20 AM4/1/14
to shiny-...@googlegroups.com, Anitha Raman

Thanks Joe, it works.

Lukáš Drápal

unread,
Jun 23, 2015, 10:10:43 AM6/23/15
to shiny-...@googlegroups.com
Hi,

I have the same problem, but I need a more robust solution. Using this solution, the user of the app can still view the message in source code in a browser, it is just hidden on the screen. I would need to get rid of the message at all (or better replace it with an universal message: "Error ocurred, please contact admin." )

Any ideas for that? It would be a lifesaver.

Thanks,
Lukas



Dne pátek 28. března 2014 20:10:57 UTC+1 Joe Cheng [RStudio] napsal(a):

Dean Attali

unread,
Jun 23, 2015, 2:15:47 PM6/23/15
to shiny-...@googlegroups.com
I haven't tried this so maybe it wouldn't work, but perhaps you could encapsulate the whole app in a tryCatch, and when you catch an error then you simply throw your own `stop("Error occurred")`.
Don't know if that'll work

Dario Strbenac

unread,
Jun 23, 2015, 8:00:13 PM6/23/15
to shiny-...@googlegroups.com
You should use validate and need functions. For example, if you want to plot a data row from a matrix with one of its row names equal to the value stored in the variable featureName, the first lines of your reactive expression should be :
 
featureName <- input[["featureChooser"]]
validate(need(!is.null(featureName), ''))

Benjamin Birnbaum

unread,
Feb 18, 2016, 4:45:35 PM2/18/16
to Shiny - Web Framework for R
I share Lukáš's concern.  The reason I want to suppress error messages is for security, and changing the style of the error messages doesn't actually make them invisible to the client.  Lukáš did you find a solution?  It would be ideal if there was a "prod-mode" of shiny server that made sure no error text ever got to the user.

Joe Cheng

unread,
Feb 19, 2016, 3:39:44 AM2/19/16
to Benjamin Birnbaum, Shiny - Web Framework for R
That's a great point. I still would be wary of completely squelching even the fact that an error has occured, since that could lead your users to rely on erroneous values thinking they were correct. What if the specific error message is replaced by a generic error message?

--
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.

Benjamin Birnbaum

unread,
Feb 19, 2016, 7:29:06 AM2/19/16
to Shiny - Web Framework for R, benjamin...@gmail.com
Yeah, I think replacing an error message with a generic 500 internal server error message would be ideal.  Is this possible now, or should this be a feature request?

Joe Cheng

unread,
Mar 2, 2016, 3:14:18 PM3/2/16
to Benjamin Birnbaum, Shiny - Web Framework for R
It is possible now by inserting this snippet into the top of either app.R, or if you have a ui.R/server.R style app, at the top of global.R (make one in the app dir if you don't have one already):

options(shiny.error = function() {
  stop("An error has occurred")
})

This has the drawback that it will fully swallow your errors, your log file will contain only nonsense like this:

Warning: Error in handle: An error has occurred
No stack trace available
Error in handle() : An error has occurred
Warning: Error in handle: An error has occurred
No stack trace available

So clearly you don't want to use this during development. You could do something like this:

if (!interactive()) {
  options(shiny.error = function() {
    stop("An error has occurred")
  })
}

which would probably work for most cases.

I think we can do better than this though; ideally there'd be an option in Shiny Server, Shiny Server Pro, and ShinyApps.io that let you specify that you want errors hidden from the client but still logged on the server side.

Anyway, I've filed an issue to track this further work:

In the meantime, please let me know if the workaround I've proposed is enough to get you unblocked. Thanks.

sri...@navgathi.com

unread,
Aug 30, 2016, 3:05:34 AM8/30/16
to Shiny - Web Framework for R
dear sir, 
   if i want to stop showing the red error message in particular tab in shiny app while loading .what is the solution for not showing that .

Laura Dawkins

unread,
Aug 31, 2016, 5:06:49 AM8/31/16
to Shiny - Web Framework for R
Hi,

I am having a similar problem where if I increase the dimension of a reactive array using a numeric input and it flashes up an error message "Warning: Error in <-: number of items to replace is not a multiple of replacement length" before then re-exicuting and working. 

I would like to have my code check whether the dependencies are ready do I don't get this error message and I have tried a lot of things to do this but cant seem sort out the issue. How would you suggest checking for these dependencies? 

This is my server code:

shinyServer(
  function(input, output) {

    outcomes <- reactive({
      input$numOutcomes
      })
    ncovs <- reactive({
      input$numCovs 
      })
    M <- reactive({
      input$numSamp     
      })

  output$sliders1 <- renderUI({
      lapply(1:(outcomes()-1), function(i) {
      sliderInput(paste0("mu", i), label = h4(withMathJax('\\(\\mu_{',(i+1),'0}\\)')),
        min = -10, max = 10, value = -4, step= 0.1, animate = TRUE)
      })
  })

  output$sliders2 <- renderUI({
      lapply(1:(outcomes()-1), function(i) {
      sliderInput(paste0("sigma", i), label = h4(withMathJax('\\(\\sigma_{',(i+1),'0}\\)')),
        min = 0, max = 3, value = 0.1, step= 0.05, animate = TRUE)
      })
    })

  output$covranges <- renderUI({
      lapply(1:ncovs(), function(i) {
      sliderInput(paste0("covrange", i), label = h4(withMathJax('\\(x_{',i,'}\\)')),
        min = -10, max = 10, value = c(0,4))
      })
    })

#plots

    Create_mu <- reactive({ 
      mu <- array(0,dim=c((outcomes()-1),(ncovs()+1)))
        for(i in 1:(outcomes()-1)){
        mu[i,1] <- input[[paste0("mu",i)]]
    }
    mu
    })

    #mu[2:(r-1),] = 0

    Create_sigma <- reactive({ 
      sigma <- array(0.5,dim=c((outcomes()-1),(ncovs()+1)))      
      for(i in 1:(outcomes()-1)){
        sigma[i,1] <- input[[paste0("sigma",i)]]
    }
    sigma
    })
    #sigma[2:(r-1),] = 0.5
    
    Create_ranges <- reactive({ 
      ranges <- array(dim=c(ncovs(),2))
        for(i in 1:ncovs()){
        ranges[i,] <- input[[paste0("covrange",i)]]
    }
    ranges
    })


output$thetas <- renderPlot({
  use_r <- input$numOutcomes
  use_C <- input$numCovs
  use_M <- input$numSamp
  use_mu <- Create_mu()
  use_sigma <- Create_sigma()
  use_ranges <- Create_ranges()

  theta_plot(r=use_r,C=use_C,M=use_M,mu=use_mu,sigma=use_sigma,ranges=use_ranges)
})

Any help would be greatly appreciated!

Thank you,
Laura
Reply all
Reply to author
Forward
Message has been deleted
0 new messages