tabpanel 的动态高度调整不适用于信息框

Dynamic height adjustment of tabpanel does not work with infobox

我正在创建一个闪亮的仪表板,并希望在选项卡面板中使用信息框。但是面板的高度不会动态调整到信息框的高度。如果我在面板中集成图表,它会自动调整。

我的代码如下所示:

library("shiny")
library("shinydashboard")
library("shinydashboardPlus")

ui <- dashboardPage(
    header =     dashboardHeader()
    ,sidebar = dashboardSidebar()
    ,body = dashboardBody(
        
        tabBox(
            tabPanel(
                title = "Tab1"
                ,infoBoxOutput(outputId = "ibo")
            )
            ,tabPanel(
                title = "Tab2"
                ,plotOutput(outputId = "po")
            )
            ,width = 12
        )
        
    )
)

server <- function(input, output) {
    
    output$ibo <- renderInfoBox({
        infoBox(
            title = "Infobox"
            ,value = 42
        )
    })
    
    output$po <- renderPlot({
        plot(mtcars$mpg, mtcars$cyl)
    })
    
}

shinyApp(ui = ui, server = server)

如何将标签面板的高度调整为信息框的高度?

很简单,将 infoBoxOutput 包裹在 fluidRow 中:

library("shiny")
library("shinydashboard")
library("shinydashboardPlus")

ui <- dashboardPage(
    header =     dashboardHeader()
    ,sidebar = dashboardSidebar()
    ,body = dashboardBody(
        
        tabBox(
            tabPanel(
                title = "Tab1",
                fluidRow(
                    infoBoxOutput(outputId = "ibo")
                )
            )
            ,tabPanel(
                title = "Tab2"
                ,plotOutput(outputId = "po")
            )
            ,width = 12
        )
        
    )
)

server <- function(input, output) {
    
    output$ibo <- renderInfoBox({
        infoBox(
            title = "Infobox"
            ,value = 42
        )
    })
    
    output$po <- renderPlot({
        plot(mtcars$mpg, mtcars$cyl)
    })
    
}

shinyApp(ui = ui, server = server)