Combining renderUI, dataTableOutput, and renderDataTable

孤者浪人 提交于 2021-02-11 14:17:23

问题


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:


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))


来源:https://stackoverflow.com/questions/61299679/combining-renderui-datatableoutput-and-renderdatatable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!