I think there are a couple things that need to be addressed in this question. First of all, the place you would put the server logic, such that it drives a specific output, is in the server function. In the renderText
function, you can put any type of interactive expression. In your case, this might be
output$name <- renderText({
if(input$name != ""){
paste0("Oh hai Mr. ", input$name, ". How are you?"
}
})
At the same time, this doesn't have any control flow other than not displaying while a name is blank. Instead, you might want to consider adding a submitButton
or actionButton
in order to allow people to submit their name once they are finished typing this.
Here is how you would include that:
sidebarPanel(
textInput("name","Enter your name",""),
actionButton(inputId = "submit",label = "Submit")
)
To access the actionButton's control flow, you can set up a reactive expression triggered by the event. For example, we are going to call it "name."
name <- eventReactive(input$submit, {
if(input$name != ""){
paste0("Oh hai Mr. ", input$name, ". How are you?")
} else {
"Please write a name."
}
})
Then when we want to refer to it, we can use it in our call to output$name like so:
output$name <- renderText({
name()
})
This way, people's names will only appear once they have actually written a name, and otherwise they get an error message prompting them to write something.