tabpanel and wasted white space

倾然丶 夕夏残阳落幕 提交于 2019-12-11 02:56:57

问题


I am creating a simple shiny app with some valuebox and three datatables.

If I design the app without using tabpanel everything works fine.

library(shiny)
library(shinydashboard)
library(DT)

ui <- dashboardPage(
  dashboardHeader(title = "Dynamic boxes"),
  dashboardSidebar(),
  dashboardBody(
    fluidRow(

      valueBoxOutput("vbox1", width = 2),
      valueBoxOutput("vbox2", width = 2),
      valueBoxOutput("vbox3", width = 2),
      valueBoxOutput("vbox4", width = 2),
      valueBoxOutput("vbox5", width = 2),
      valueBoxOutput("vbox6", width = 2)


    ),

    fluidRow(

      column(width = 4,  box(title = "Iris", width = NULL, solidHeader = FALSE, dataTableOutput("dat1"))),
      column(width = 4,  box(title = "MT Cars", width = NULL, solidHeader = FALSE, dataTableOutput("dat2"))),
      column(width = 4,  box(title = "Old Faithful Gyser", width = NULL, solidHeader = FALSE, dataTableOutput("dat3")))

  ))
  )


server <- function(input, output) {

  output$vbox1 <- renderValueBox({ valueBox( "One","Yes",icon = icon("stethoscope"))})
  output$vbox2 <- renderValueBox({ valueBox( "Two","Yes",icon = icon("stethoscope"))})
  output$vbox3 <- renderValueBox({ valueBox( "Skip","Yes",icon = icon("stethoscope"))})
  output$vbox4 <- renderValueBox({ valueBox( "a Two","Yes",icon = icon("stethoscope"))})
  output$vbox5 <- renderValueBox({ valueBox( "Then","Yes",icon = icon("stethoscope"))})
  output$vbox6 <- renderValueBox({ valueBox( "some","Yes",icon = icon("stethoscope"))})

  output$dat1 <- renderDataTable({datatable(iris)})
  output$dat2 <- renderDataTable({datatable(mtcars,extensions = 'Responsive' )})
  output$dat3 <- renderDataTable({datatable(faithful,rownames = FALSE, options = list(autoWidth = TRUE)  )})
}

shinyApp(ui, server)

Now if I design the app using tabpanel function there is a lot of wasted white space on the rightside.

library(shiny)
library(shinydashboard)
library(shinyBS)
library(DT)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(
    sidebarPanel(
                     textInput("text", "Enter Id:"),
                     box(width = 1, background  = 'purple'),
                     actionButton("Ok", "Press Ok",style='padding:8px; font-size:100%')
    )

  ),
  dashboardBody(

    mainPanel(

      tabsetPanel(

        tabPanel("About", value=1, h6("The objective is to test width of ShinyApp in tabPanel design", br(),
                                      br(),

                                      "Distribution Prototype"

                                        )
                  ),


        tabPanel("Data", value=2,

                        fluidRow(

                          valueBoxOutput("vbox1", width = 2),
                          valueBoxOutput("vbox2", width = 2),
                          valueBoxOutput("vbox3", width = 2),
                          valueBoxOutput("vbox4", width = 2),
                          valueBoxOutput("vbox5", width = 2),
                          valueBoxOutput("vbox6", width = 2)


                        ),

                        fluidRow(

                          column(width = 4,  box(title = "Iris", width = NULL, solidHeader = FALSE, dataTableOutput("dat1"))),
                          column(width = 4,  box(title = "MT Cars", width = NULL, solidHeader = FALSE, dataTableOutput("dat2"))),
                          column(width = 4,  box(title = "Old Faithful Gyser", width = NULL, solidHeader = FALSE, dataTableOutput("dat3"))))

                      )
                )
              )
  ))

server <- function(input, output) {

  output$vbox1 <- renderValueBox({ valueBox( "One","Yes",icon = icon("stethoscope"))})
  output$vbox2 <- renderValueBox({ valueBox( "Two","Yes",icon = icon("stethoscope"))})
  output$vbox3 <- renderValueBox({ valueBox( "Skip","Yes",icon = icon("stethoscope"))})
  output$vbox4 <- renderValueBox({ valueBox( "a Two","Yes",icon = icon("stethoscope"))})
  output$vbox5 <- renderValueBox({ valueBox( "Then","Yes",icon = icon("stethoscope"))})
  output$vbox6 <- renderValueBox({ valueBox( "some","Yes",icon = icon("stethoscope"))})

  output$dat1 <- renderDataTable({datatable(iris)})
  output$dat2 <- renderDataTable({datatable(mtcars,extensions = 'Responsive' )})
  output$dat3 <- renderDataTable({datatable(faithful,rownames = FALSE, options = list(autoWidth = TRUE)  )})

}

shinyApp(ui, server)

Wasted White Space Image

My usecase dictates that I use tabpanel, so any suggestions on making these objects span across the entire layout without wasting space is much appreciated.

来源:https://stackoverflow.com/questions/46184346/tabpanel-and-wasted-white-space

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!