简体   繁体   中英

Using columns to control tabBox content in Shiny dashboard

I'm trying to build a Shiny dashboard page which will have tabbed pages with different types of plots, allow users to change settings dynamically, etc. Starting with the standard demo code from the Shiny Dashboards page, I can get a stacked version of the page ( 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"))
     }
  )

If I modify line 10 to this:

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

I get the heading and the boxplot split into columns, but the tabBox no longer expands to contain them.

Is there any way to control the contents of the tabPanel to allow columnar formatting of the output?

Just wrap your columns inside a fluidRow or fluidPage . Then the tabPanel gets the right size and stretches out to fit your columns.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM