使用列控制 Shiny 仪表板中的 tabBox 内容

Using columns to control tabBox content in Shiny dashboard

我正在尝试构建一个 Shiny 仪表板页面,该页面将包含带有不同类型图表的标签页,允许用户动态更改设置等。从 Shiny Dashboards 页面的标准演示代码开始,我可以得到页面的堆叠版本 (https://rstudio.github.io/shinydashboard/structure.html#tabbox):

library(shiny)
  library(shinydashboard)

  body <- dashboardBody(
     fluidRow(
        tabBox(
           title = "First tabBox",
           # The id lets us use input$tabset1 on the server to find the current tab
           id = "tabset1", 
           tabPanel("Tab1", "First tab content", plotOutput('test')),
           tabPanel("Tab2", "Tab content 2")
        ),
        tabBox(
           side = "right", 
           selected = "Tab3",
           tabPanel("Tab1", "Tab content 1"),
           tabPanel("Tab2", "Tab content 2"),
           tabPanel("Tab3", "Note that when side=right, the tab order is reversed.")
        )
     ),
     fluidRow(
        tabBox(
           # Title can include an icon
           title = tagList(shiny::icon("gear"), "tabBox status"),
           tabPanel("Tab1",
                    "Currently selected tab from first box:",
                    verbatimTextOutput("tabset1Selected")
           ),
           tabPanel("Tab2", "Tab content 2")
        )
     )
  )

  shinyApp(
     ui = dashboardPage(
        dashboardHeader(title = "tabBoxes"),
        dashboardSidebar(),
        body
     ),
     server = function(input, output) {
        # The currently selected tab from the first box
        output$tabset1Selected <- renderText({
           input$tabset1
        })
        output$test = renderPlot(
           boxplot(len ~ dose, data = ToothGrowth,
             boxwex = 0.25, at = 1:3 - 0.2,
             subset = supp == "VC", col = "yellow",
             main = "Guinea Pigs' Tooth Growth",
             xlab = "Vitamin C dose mg",
             ylab = "tooth length",
             xlim = c(0.5, 3.5), ylim = c(0, 35), yaxs = "i"))
     }
  )

如果我将第 10 行修改为:

tabPanel("Tab1", column(4,"First tab content"), 
                 column(8, plotOutput('test'))
                 ),

我将标题和箱线图拆分成列,但 tabBox 不再扩展以包含它们。

有什么方法可以控制 tabPanel 的内容以允许输出的分栏格式吗?

只需将您的列包裹在 fluidRowfluidPage 中。然后 tabPanel 获得合适的尺寸并伸展以适合您的列。