【问题标题】:shinydashboard: strange rendering when using uiOutput() for bodyshinydashboard:使用 uiOutput() 进行正文时出现奇怪的渲染
【发布时间】:2018-08-24 08:41:39
【问题描述】:

我希望我的 dahsboardbody 根据侧边栏中的选择进行更改。但是,我对生成的主体渲染有一个问题,如下所示:

wrong rendering

框的宽度 = 12,因此应该像这样覆盖整个 Row:

correct rendering

这是我正在使用的代码:

body1 <- dashboardBody(
     box(title = "test1", width = 12)
)

body2 <- dashboardBody(
  box(title = "test2", width = 12)
)

sidebar <- dashboardSidebar(
  sidebarMenu(
    menuItem("Choose", tabName = "test",
             radioButtons("choice", label = NULL, choices = c("body1", "body2"))
    )
  )
)

body <- dashboardBody(uiOutput("body"))

ui <- dashboardPage(
  header = dashboardHeader(),
  sidebar = sidebar,
  body = body1
)

server <- function(input, output, session) {
  
  output$body <- renderUI({
    if(input$choice == "body1") {
      body1
    }
    else {
      body2
    }
  })
}

shinyApp(ui, server)

调整窗口大小或在浏览器中打开它没有帮助。我错过了什么?

我正在使用 R 版本 3.5.0 (2018-04-23) 与 shinydashboard_0.7.0 和 shiny_1.1.0。

非常感谢您的帮助!

【问题讨论】:

  • 您的代码非常适合我,就像正确渲染一样。

标签: r shiny rendering data-science shinydashboard


【解决方案1】:

尝试将dashboardPage()body 参数设置如下:

ui <- dashboardPage(
  header = dashboardHeader(),
  sidebar = sidebar,
  body = dashboardBody(uiOutput("body"))
)

此外,从 body1body2 变量中删除 dashboardBody() 包装器:

body1 <- box(title = "test1", width = 12)
body2 <- box(title = "test2", width = 12)

它将解决动态主体问题,也可能解决您的渲染问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-15
    • 1970-01-01
    相关资源
    最近更新 更多