Reputation: 133
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.
Upvotes: 8
Views: 3723
Reputation: 12654
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.
Upvotes: 7