library(shiny)

#Reference: http://stackoverflow.com/questions/19624461/r-shiny-iterate-over-shinyui-output-elements

ui <- list(
    textInput('text1', 'Text 1', value=''),
    textInput('text2', 'Text 2', value=''),
    textInput('text3', 'Text 3', value=''),
    hr(),
    textOutput('out1'),
    textOutput('out2'),
    textOutput('out3')
)


server1 <- function(input, output) {
    output$out1 <- renderText({ input$text1 })
    output$out2 <- renderText({ input$text2 })
    output$out3 <- renderText({ input$text3 })    
}


server2 <- function(input, output) {
    for (i in 1:3) {
        output[[paste('out', i, sep='')]] <- renderText({
            input[[paste('text', i, sep='')]]
        })
    }
    #i <- 1
}


server3 <- function(input, output) {
    lapply(1:3, 
        function(i) { output[[paste('out', i, sep='')]] <- renderText({ input[[paste('text', i, sep='')]] }) }
    )
}


server4 <- function(input, output) {
    for (i in 1:3) { local({
        j <- i
        output[[paste('out', j, sep='')]] <- renderText({
            input[[paste('text', j, sep='')]]
        })
    }) }
}


#runApp(list(ui=ui, server=server1))  # works but lengthy
#runApp(list(ui=ui, server=server2))  # does not work
runApp(list(ui=ui, server=server3))  # works
#runApp(list(ui=ui, server=server4))  # works
