1

Suppose I have the following shiny app that renders a data table from the package DT:

library(shiny)
ui <- fluidPage(uiOutput("abc"))
server <- function(input, output, session) {
  output$abc <- renderUI({DT::dataTableOutput("dt_output")})               # line 4
  output$dt_output <- DT::renderDataTable({data.table(a = 1:3, b = 4:6)})  # line 5
}
runApp(list(ui = ui, server = server))

How would you combine lines 4 and 5, with the constraint that output$abc must remain a uiOutput?

My attempt at combining (the code below) led to an error, "cannot coerce type closure":

output$abc <- renderUI({DT::dataTableOutput(
    DT::renderDataTable({data.table(a = 1:3, b = 4:6)}))})

1 Answer 1

2

This should work:

library(shiny)

ui <- fluidPage(
    uiOutput("abc")
)

server <- function(input, output, session) {

    output$abc <- renderUI({
        output$aa <- DT::renderDataTable(head(mtcars))
        DT::dataTableOutput("aa")
    })

}
runApp(list(ui = ui, server = server))
Sign up to request clarification or add additional context in comments.

1 Comment

Haha, I was trying to avoid using two arrows, but this works! Thanks again, Pork Chop!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.