R markdown report preview

I am trying to modify this example in order to preview the report in the main UI panel prior to downloading it but no luck so far.

shinyApp(
  ui = fluidPage(
    sidebarLayout(
      sidebarPanel(
          sliderInput("slider", "Slider", 1, 100, 50),
          downloadButton("report", "Generate report")),

      mainPanel(
        uiOutput('reportUi')
      )
    )  

  ),
  server = function(input, output) {

    output$report <- downloadHandler(
      filename = "report.html",
      content = function(file) {
        tempReport <- file.path(tempdir(), "report.Rmd")
        file.copy("report.Rmd", tempReport, overwrite = TRUE)

        # Set up parameters to pass to Rmd document
        params <- list(n = input$slider)

        # Knit the document, passing in the `params` list

        rmarkdown::render(tempReport, output_file = file,
                          params = params,
                          envir = new.env(parent = globalenv())
        )
      }
    )



    output$reportUi <- renderUI({

        tempReportUi <- file.path(tempdir(), "report.Rmd")
        file.copy("report.Rmd", tempReportUi, overwrite = TRUE)

        # Set up parameters to pass to Rmd document
        paramsUi <- list(n = input$slider)

        rmarkdown::render(tempReportUi, output_file = file,
                          params = paramsUi,
                          envir = new.env(parent = globalenv()))        
    })

  }
)

I have been trying that as well for a couple days. Where you able to find a solution for that?