title: R Shiny: Switch between table and plot in renderUI
body: <p>I am trying to let the user select the kind of display he wishes, but when I try to render the plot it gives me an error.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>library(shiny)
  library(DT)
  library(data.table)
  
  runApp(list(
      ui = fluidPage(
          wellPanel(
              radioButtons("visuBtn", NULL, choices = c(Table = "table", Plot = "plot"))
          ),
          wellPanel(
              uiOutput("DataTable")
          )
      ),
      server = function(input, output){
  
          observeEvent(input$visuBtn,{
              output$DataTable &lt;- renderUI({
                  dfconc &lt;- data.table(time = c(1,2,3,4,5), concentration = c(0.1, 0.4, 0.5, 0.7, 0.8))
  
                  if(input$visuBtn == "table"){
                      output$aa &lt;- renderDataTable(dfconc, options = list(paging = FALSE, searching = FALSE))
                      dataTableOutput("aa")
                  }
                  else { ### NOT WORKING
                      output$aa &lt;- renderPlot({
                          plot(dfconc$time, dfconc$concentration, xlab = "Time", ylab = "Concentration")
                      })
                      fixedRow(
                          plotOutput("aa")
                      )
                  }      ###
  
              })
          })
      }
  ))
  
  
  </code></pre>
  
  <p>Thanks for your help</p>