Simply, I have a Shiny app, where users can select various combinations of values in a data set and produces a graph. However for some of those combinations there is no data and Shiny produces an error message:
Error: 'from' must be length 1
How can I replace this error message with a more informative message, like:
Sorry, there is no data for you requested combination. Please change your input selections
Thanks.
You can add content to your Shiny app by placing it inside a *Panel function. For example, the apps above display a character string in each of their panels. The words “sidebar panel” appear in the sidebar panel, because we added the string to the sidebarPanel function, e.g. sidebarPanel("sidebar panel") .
Error sanitization applies to all errors generated within your app: both the ones you yourself produce using stop() , and the ones produced by code you rely on (although, ultimately, some code somewhere will have had to use a stop() or a similar function for an error to occur).
Simply call shinyalert() with the desired arguments, such as a title and text, and a modal will show up. In order to be able to call shinyalert() in a Shiny app, you must first call useShinyalert() anywhere in the app's UI.
But the simplest way to run a Shiny app is to run it locally. You only need the shiny R package installed, and you can run the app in your browser.
You can do this using the validate
and need
functions. The code would look something like this:
output$MyPlot<-renderPlot({
validate(
need(MyData(), "Sorry, there is no data for you requested combination.
Please change your input selections"
)
)
...code for making plot...
})
If the MyData()
part does not exist due to giving an error, than the message will display, otherwise the plot will. Check ?validate
for all the details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With