10.4 Creating UI with code

Create and modify the user interface while the app is running


The last two functions uiOutput() and renderUI(), are for applying the technique of rendering the UI by setting the value of the new input to the current value of the existing control.

This technique gives the developer the ability to create and modify the user interface while the app is running.

uiOutput() act in the UI part of the app while renderUI() act in the Server.

In this contest the function isolate() would be able to do this isolating a particular input, for more info see: Section 15.4.1

Final example to show the position of the two functions inside the UI and the Server:

##############################################

ui <- fluidPage(
  selectInput("type", "type", c("slider", "numeric")),
  
  uiOutput("numeric")
)

###############################################
server <- function(input, output, session) {
  
  output$numeric <- renderUI({
    
    if (input$type == "slider") {
      sliderInput("n", "n", value = 0, min = 0, max = 100)
    } else {
      numericInput("n", "n", value = 0, min = 0, max = 100)  
    }
  })
}
####################################

In addition to the aforementioned functions more features are available as a composition of each other and many more, to allow the user for Multiple controls, Dynamic filtering and Dialog boxes.