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

时间:2016-03-31 00:04:31

标签: r shiny shinydashboard

我正在尝试构建一个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'))
                 ),

我得到标题并将boxplot拆分成列,但tabBox不再展开以包含它们。

有没有办法控制tabPanel的内容以允许输出的列式格式?

1 个答案:

答案 0 :(得分:4)

只需将列包裹在fluidRowfluidPage内。然后tabPanel得到正确的尺寸并延伸到适合您的列。