Validation inside of an observe event

I am a little confused about the difference between req and validate in R shiny. The only real difference I can see is that validate gives a message to the user. I am building an interface and was using a bunch of hidden messages and conditional statements. I would like to condense my code and like the idea of using validate. I only want to show my message when the user tries to click the button and tries to continue to another part of the UI.

I provide a simplified version of the code, the message "Success" will only show when the text input for the id and the agreement button is clicked. If one or both are missing, a conditional panel will display the validation text.

I am concerned that displaying an output inside of an action button destroys the environment and essentially turns it into a reactive environment. I used the req after the validation check so that the success message will not display unless the input is provided for both. Is this the best way to do this? Or is there a more efficient/proper way? My main concern is that when I build up the complexity, I will break the app.


ui <- fluidPage(
      textInput(inputId = "id",
                label = 'Please enter your id'
      checkboxInput("agree", label = "I agree", value = FALSE),
      conditionalPanel(condition = " == '' || !input.agree",
      actionButton("submit_info", "Submit"),

server <- function(input, output) {
  observeEvent(input$submit_info, {
    output$error_msg <- renderText({
        shiny::need(input$id != '', 'You must enter your id above to continue.'
        shiny::need(input$agree, "You must agree to continue")
    output$success_msg <- renderText({"Success"})

shinyApp(ui = ui, server = server)