shinydashboard中的间距/填充问题

时间:2017-06-15 22:26:40

标签: r shiny shinydashboard

我是shinydashboard的首次使用者,而且我无法理解页面上图表中框之间填充的工作原理。例如,下面示例中的填充非常混乱,并且准确地表示了我在工作中遇到的问题:

enter image description here

如何拉伸图表(理想情况下将框之间的填充设置为0)?

以下是用于创建上述图片的代码:

library(shinydashboard)

header <- dashboardHeader()

sidebar <- dashboardSidebar(
    sidebarMenu(
      sliderInput("bins",
                  "Number of bins:",
                  min = 1,
                  max = 50,
                  value = 30)
      )
    )

body <- dashboardBody(
    fluidRow(
        column(
            width = 4,
        box(title = "Chart1",
                plotOutput("distPlot")
            )
        ),
        column(
            width = 6,
            tabBox(
                tabPanel(id = "tabBox1",
                         title = "Chart2",
                         plotOutput("distPlot2")
                         ),
                tabPanel(id = "tabBox2",
                         title = "Chart3",
                         plotOutput("distPlot3")
                         ),
                tabPanel(id = "tabBox3",
                         title = "Chart4",
                         plotOutput("distPlot4")
                         )
                )
            ),
        column(width = 2,
                     box(title = "Chart5",
                         plotOutput("distPlot5")
                         )
                     )
        )
    )

shinyApp(
    ui = dashboardPage(header, sidebar, body),
    server = function(input, output) {
      output$distPlot <- renderPlot({
        x    <- faithful[, 2]
        bins <- seq(min(x), max(x), length.out = input$bins + 1)
        hist(x, breaks = bins, col = 'darkgray', border = 'white')
      })

      output$distPlot2 <- renderPlot({
        x    <- faithful[, 2]
        bins <- seq(min(x), max(x), length.out = input$bins + 1)

        hist(x, breaks = bins, col = 'darkgray', border = 'white')
      })

      output$distPlot3 <- renderPlot({
        x    <- faithful[, 2]
        bins <- seq(min(x), max(x), length.out = input$bins + 1)
        hist(x, breaks = bins, col = 'darkgray', border = 'white')
      })

      output$distPlot4 <- renderPlot({
        x    <- faithful[, 2]
        bins <- seq(min(x), max(x), length.out = input$bins + 1)
        hist(x, breaks = bins, col = 'darkgray', border = 'white')
      })

      output$distPlot5 <- renderPlot({
        x    <- faithful[, 2]
        bins <- seq(min(x), max(x), length.out = input$bins + 1)
        hist(x, breaks = bins, col = 'darkgray', border = 'white')
      })
    }
)

1 个答案:

答案 0 :(得分:1)

您也可以通过指定框的宽度(到12)来实现:

body <- dashboardBody(
  fluidRow(
    column(
      width = 4,
      box(title = "Chart1", width = 12,
          plotOutput("distPlot")
      )
    ),
    column(
      width = 6,
      tabBox(width = 12,
        tabPanel(id = "tabBox1",
                 title = "Chart2",
                 plotOutput("distPlot2")
        ),
        tabPanel(id = "tabBox2",
                 title = "Chart3",
                 plotOutput("distPlot3")
        ),
        tabPanel(id = "tabBox3",
                 title = "Chart4",
                 plotOutput("distPlot4")
        )
      )
    ),
    column(width = 2,
           box(title = "Chart5", width = 12,
               plotOutput("distPlot5")
           )
    )
  )
)