【问题标题】:Using renderDataTable within renderUi in Shiny在 Shiny 的 renderUi 中使用 renderDataTable
【发布时间】:2015-08-04 15:40:04
【问题描述】:

我正在试验一个闪亮的应用程序来显示动态上下文,但我无法让 renderDataTable 工作到 renderUi 组件中。 下面是两个简单的可复制测试:第一个不工作,第二个没有renderUi 工作正常,当然。

这两者在概念上有何区别,为什么第一个不能在Shiny 中工作?

这个不起作用:请注意,uiOutput myTable 包含两个反应组件,一个selectInput 和一个renderDataTable,但只呈现selectInput

library(shiny)
runApp(list(
    ui = fluidPage(
            fluidRow(h2("where is the table?")),
            uiOutput('myTable')
    ),
    server = function(input, output) {
            output$myTable <- renderUI({
                    fluidPage(
                            fluidRow(selectInput("test", "test", c(1,2,3))),
                            fluidRow(renderDataTable(iris))
                    )
            })
    }
))

这很好,selectInputrenderDataTable 都被渲染了:

library(shiny)
runApp(list(
    ui = fluidPage(
            fluidRow(h2("where is the table?")),
            fluidRow(selectInput("test", "test", c(1,2,3))),                
            fluidRow(dataTableOutput('myTable'))
    ),
    server = function(input, output) {
            output$myTable = renderDataTable(iris)
    }
))

如何让第一个场景工作?

谢谢。

亿辉评论后编辑(感谢亿辉):

renderUi 中必须使用一些ui 函数,而不是一些渲染函数: 以正确的方式更改示例代码,结果没有改变:仍然没有显示数据。

library(shiny)
runApp(list(
    ui = basicPage(
            uiOutput('myTable')
    ),
    server = function(input, output) {
            output$myTable <- renderUI({dataTableOutput(iris)
            })
    }
))

编辑 n.2

刚刚解决,可以正常工作了:

library(shiny)
runApp(list(
    ui = fluidPage(
            mainPanel(

                    uiOutput('myTable')
            )
    ),
    server = function(input, output) {
            output$myTable <- renderUI({
                    output$aa <- renderDataTable(iris)
                    dataTableOutput("aa")
            })
    }
))

我必须先将renderTableOutput 保存在输出变量中,然后将其提供给dataTableOutput

感谢您指点我:here

【问题讨论】:

  • 感谢一辉,在查看了您在groups.google.com/d/msgid/shiny-discuss/… 的回答后,我用新代码更新了问题。 ,但仍然没有运气。
  • 我不明白你为什么要把renderDataTable“封装”在renderUI里面……如果你必须创建一个“复杂的结构”,你不能用fluidPage/ fluidRow/column/div/... 有一个或多个*output?
  • 虽然第二次编辑可能有效,但每次刷新 output$myTable 时,您都在重新定义 output$aa,而不是让反应模型工作。更有效的方法如@Thomas 的回答中所述

标签: r shiny renderer


【解决方案1】:

如果将datatable代和ui代的部分分开会更清楚:

library(shiny)
runApp(list(
    ui = fluidPage(
            mainPanel(
                    uiOutput('myTable')
            )
    ),
    server = function(input, output) {
            output$aa <- renderDataTable({iris})
            output$myTable <- renderUI({
                    dataTableOutput("aa")
            })
    }
))

【讨论】:

    猜你喜欢
    • 2017-11-26
    • 1970-01-01
    • 2018-08-11
    • 2020-08-01
    • 2019-12-21
    • 1970-01-01
    • 1970-01-01
    • 2015-01-19
    • 2020-05-14
    相关资源
    最近更新 更多