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")
)
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.
library(shiny)
print(need("A" %in% c("A", "B"), "The value is something other than 'A' or 'B'"))
#> NULL
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'"
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.