Return full HTML content of renderUi in R shiny

Viewed 377

Is it possible to get the full HTML text of a page, which is generated as renderUi object in shiny? I would need the content to generate a screenshot using ajax.

Example 1 works as expected: The page is gererated directly in the ui. The resulting ui object comprises the full HTML text. It can be saved as .html file and opened in an browser to display the page.

ui <- fluidPage(
  div(numericInput("invalue", label = "Input", 10)),
  h4(div("Output")),
  textOutput("outvalue")
)

server <- function(input, output, session) {
output$outvalue <- renderText(input$invalue * 10)
}

shinyApp(ui, server)

ui content:

<div class="container-fluid">
  <div>
    <div class="form-group shiny-input-container">
      <label for="invalue">Input</label>
      <input id="invalue" type="number" class="form-control" value="10"/>
    </div>
  </div>
  <h4>
    <div>Output</div>
  </h4>
  <div id="outvalue" class="shiny-text-output"></div>
</div>

Example 2 does not work properly: The page is gererated on server side using renderUI and sent to the ui function, where it is processed through uiOutput. The page looks exactly the same as in example 1, but the resulting ui object comprises only one line. If it is saved as .html file and opened in an browser it shows nothing.

ui <- uiOutput("page")

server <- function(input, output, session) {
  output$outvalue <- renderText(input$invalue * 10)
  output$page <- renderUI({
    fluidPage(
      div(numericInput("invalue", label = "Input", 10)),
      h4(div("Output")),
      textOutput("outvalue")
    )
  })
}

shinyApp(ui, server)

ui content:

<div id="page" class="shiny-html-output"></div>

So the question is: Is it posssible to obtain the full HTML content from example 2? I would need this to generate an ajax screenshot from a page, which is generated dynamically using renderUi.

0 Answers
Related