【问题标题】:Dynamic height adjustment of tabpanel does not work with infobox选项卡面板的动态高度调整不适用于信息框
【发布时间】:2022-01-01 02:57:18
【问题描述】:

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

我的代码如下所示:

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)

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

【问题讨论】:

    标签: r shiny dashboard tabpanel infobox


    【解决方案1】:

    非常简单,将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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-26
      • 2018-05-16
      • 2012-08-29
      • 1970-01-01
      • 1970-01-01
      • 2019-09-27
      相关资源
      最近更新 更多