When the user selects 0 input variables for a shiny plot, I would like to display a big error message instead of the plot. Using the validate() and methods from this answer I am only able to display a custom error message at either the top/bottom of the plot. Then there is a large empty white space where the plot used to be. How can I format a textoutput/error message to my liking so that it only shows up when the plot can not be rendered.
...#server.R
output$pairsPlot <- renderPlot({
output$displayvars <- renderText("")
if (length(input$display) >= 2) { #method 1
#method 2
validate(need(length(input$display)>=2, "Please select two or more display variables."))
if (input$autoRender == TRUE) {
vars <- varsList()
data <- colorData()
} else {
vars <- slowVarsList()
data <- slowData()
}
print("Rendering Plot.")
pairs(data[vars],
lower.panel = panel.smooth,
upper.panel=NULL,
col=data$color,
pch = as.numeric(input$pointStyle),
cex = as.numeric(input$pointSize))
# }
print("Plot Rendered.")
}
else {
output$displayvars <- renderText("need more display vars") #method 1
}
})
...ui.R
column(9,
h2(textOutput("displayvars"), align = "center"),
plotOutput("pairsPlot", click = "pairs_click", height=700)
)
As you can see in the code, there are two error reporting methods in place (1. if/else textoutput; 2. validate) (the validate is being overridden by the first method)