Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print error messages from R console instead of force closing shiny app #2894

Closed
melissagwolf opened this issue May 14, 2020 · 3 comments
Closed

Comments

@melissagwolf
Copy link

I have a shiny app that runs a monte carlo simulation with 500 replications. To do this, I use a for loop and call a function from another package to run the simulation, and then I save the data. The shiny app then produces the results using renderTable.

It is possible that the user could mistakenly enter something that would cause one or more of the simulation replications to fail to converge, triggering a stop in the function I'm calling. If this happens, there is nothing to render in a table. In R, I get a nice error message from the package telling me that the model failed to converge. However, in Shiny, the app just force closes.

I've tried using tryCatch and showNotification. It does show the error briefly, but the app still force closes. I've tried using a validate statement in renderTable to tell it to only render a table if the object exists, but it fails before it gets to the renderTable part of the code. Essentially, the stop function in the function I'm calling will crash the entire app if the user inputs something that triggers the stop function.

Is it possible for Shiny to simply print the fatal error message from the R console instead of defaulting to closing the app?

@melissagwolf
Copy link
Author

It seems like this may have been a deliberate design choice but could possibly be revised - if so, I would like to express support for printing error messages instead of force closing the app! https://community.rstudio.com/t/prevent-observer-crashes/25169/3

@jcheng5
Copy link
Member

jcheng5 commented May 14, 2020

Hmmm. The app shouldn’t close if you’re catching it with tryCatch. Can you show a reproducible example that you can’t stop from closing?

@melissagwolf
Copy link
Author

Creating a reprex always makes me realize that the problem isn't what I thought it was.

I figured out what's forcing it to close. I added a progress bar from a package called shinybusy. To get shinybusy to recognize that the app was running, I put an eventReactive statement in an observeEvent statement:

fluidPage(shinybusy::add_busy_bar(color = "#BECEE4"))
example < - eventReactive(input$go {
     #some function
})
observeEvent(input$go,{example()})

Forcing the app to observe an event that is hitting a stop function in a package is what causes the app to force close, and is also what causes the app to fail to display the error in renderTable (entirely negating the need to use tryCatch and showNotification).

If you have any advice about observeEvent encapsulating an eventReactive, I'd appreciate it! I really need a progress bar, but I can probably find another way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants