renderUI 不适用于 fillPage

renderUI does not work with fillPage

我有以下简单的工作闪亮应用程序:

if (interactive()) {
    ui <- fillPage(
        fillRow(
            fillCol(".", style = "background-color: red;", height = "10%"),
            fillCol(".", style = "background-color: blue;", height = "10%")
        )
    )
    server <- function(input, output, session) {}
    shinyApp(ui, server)
}

结果正是我想要的,但是如果我尝试使用 renderUI 实现相同的结果,我会得到一个空白页面。

我试着用下面的代码做到了:

if (interactive()) {
    ui <- fillPage(
        uiOutput("back")
    )
    server <- function(input, output, session) {
        output$back <- renderUI({
            fillRow(
                fillCol(".", style = "background-color: red;", height = "10%"),
                fillCol(".", style = "background-color: blue;", height = "10%")
            )
        })
    }
    shinyApp(ui, server)
}

这是使用 height:100% 时的典型问题。 uiOutput 的使用在 renderUI 的结果周围添加了一个 div ,不幸的是,默认情况下 div 的高度为 0。此 div 的修复设置高度也为 100%

if (interactive()) {
  ui <- fillPage(
    uiOutput("back",style = "height:100%;")
  )
  server <- function(input, output, session) {
    output$back <- renderUI({
      fillRow(
        fillCol(".", style = "background-color: red;", height = "10%"),
        fillCol(".", style = "background-color: blue;", height = "10%")
      )
    })
  }
  shinyApp(ui, server)
}

希望对您有所帮助!