组合renderUI,dataTableOutput和renderDataTable [英] Combining renderUI, dataTableOutput, and renderDataTable
本文介绍了组合renderUI,dataTableOutput和renderDataTable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有以下闪亮的应用程序,它从DT包中呈现了一个数据表:
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))
您如何结合第4行和第5行的约束,使 output $ abc
必须保持为 uiOutput
?
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)}))})
推荐答案
这应该有效:
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))
这篇关于组合renderUI,dataTableOutput和renderDataTable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文