【问题标题】:Combining renderUI, dataTableOutput, and renderDataTable结合 renderUI、dataTableOutput 和 renderDataTable
【发布时间】:2020-08-01 14:39:31
【问题描述】:

假设我有以下闪亮的应用程序,它从包 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))

如果output$abc 必须保持为uiOutput 的约束,您将如何组合第 4 行和第 5 行?

我尝试组合(下面的代码)导致错误,“无法强制类型闭包”:

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

【问题讨论】:

    标签: r shiny dt


    【解决方案1】:

    这应该可行:

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

    【讨论】:

    • 哈哈,我试图避免使用两个箭头,但这有效!再次感谢猪排!
    猜你喜欢
    • 1970-01-01
    • 2020-08-13
    • 1970-01-01
    • 2015-08-28
    • 2021-08-16
    • 2018-08-11
    • 1970-01-01
    • 2021-12-24
    • 1970-01-01
    相关资源
    最近更新 更多