2

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)

Community
  • 1
  • 1
  • Probably, instead of using built-in Shiny messages, just use `renderText` directly to display error messages. – Xiongbing Jin Jul 19 '16 at 17:56
  • `renderText` is the first method I tried. That works decently well but it still doesn't get placed in the middle where the plot is (just on the top or bottom depending on the order of statements in the ui.R file) – Will Knight Jul 19 '16 at 18:42
  • You can have the `plotOutput` and `textOutput` created dynamically on the server end using `renderUI`. Then you can output error text on certain condition, and the actual plot on all other conditions. You can also achieve similar effect on the ui side using `conditionalPanel` – Xiongbing Jin Jul 19 '16 at 19:05

0 Answers0