Validate, need doesn't show the message in renderplotly


Hi all,

I have an app with three radio buttons. I use plotly to show barchart based on user selection of radio buttons. For some selections, there is no data on x-axis of the plotly so the plot is showing up as below:

For those selections, I want to show a message that there is no data available. I used the following code in the renderPlotly, the NA graph doesn't show up but also the message is not being displayed.

validate (
need(!(input$x %in% c("A","B")),"Data is not available")

Do you know the possible solution?



Can you clarify which are the conditions where you want to have the custom message displayed? Is it:

input$x %in% c("A", "B") # then display custom message

OR is it:

!(input$x %in% c("A", "B")) # then display custom message

Or even better, make a small example app that reproduces your problem! :grin: See: Shiny debugging and reprex guide



It is the second one.

!(input$x %in% c("A", "B")) # then display custom message


Then I think you've got one too many negations in there. need() shows the message if the expression is a failure. You can see all the conditions that count as a failure in the documentation, but evaluating to FALSE is one of them.


print(need("A" %in% c("A", "B"), "The value is something other than 'A' or 'B'"))

print(need("C" %in% c("A", "B"), "The value is is something other than 'A' or 'B'"))
#> [1] "The value is something other than 'A' or 'B'"

Created on 2018-10-29 by the reprex package (v0.2.1)

To keep it straight in my head, I think of it as "I need <expr> to be true in order to pass validation! (otherwise, display my custom message)".

1 Like


Thanks but the main problem is that the message is not showing up even if I don't use the negation.



I think you'll need to try making a reproducible example (see the guide I linked above). Without that, there's not enough information here to figure out what might be going wrong.

1 Like