我正在使用Shinydashboard软件包中splitLayout()中的dashboardSidebar()函数。当我这样做时,我的splitLayout()中的输入之间存在很大的差距。

当我使用香草光泽时,我可以使用参数cellArgs = list(style="padding: 0px")控制此间隙,但这在dashboardSidebar()中似乎有不同的效果。

题:
如何控制splitLayout()dashboardSidebar()内部输入之间的间隔?

这是MRE,它显示了我在使用padding时失败的尝试

library(shinydashboard)
library(shiny)

sidebar <- dashboardSidebar(width=400,
                            sidebarMenu(
                              menuItem("Default", tabName = "dashboard", icon = icon("dashboard"),startExpanded = T,
                                       splitLayout(cellWidths = c(100,100,100,100),
                                                   textInput("a1",label=NULL,value = 1),
                                                   textInput("a2",label=NULL,value = 2),
                                                   textInput("a3",label=NULL,value = 3),
                                                   textInput("a4",label=NULL,value = 4)
                                       ),
                                       splitLayout(cellWidths = c(100,100,100,100),cellArgs = list(style="padding: 0px"),
                                                   textInput("b1",label=NULL,value = 1),
                                                   textInput("b2",label=NULL,value = 2),
                                                   textInput("b3",label=NULL,value = 3),
                                                   textInput("b4",label=NULL,value = 4)
                                       ),
                                       #see the effect of padding
                                       splitLayout(cellWidths = c(100,100,100,100),cellArgs = list(style="padding: 20px"),
                                                   textInput("c1",label=NULL,value = 1),
                                                   textInput("c2",label=NULL,value = 2),
                                                   textInput("c3",label=NULL,value = 3),
                                                   textInput("c4",label=NULL,value = 4)
                                       )
                              )
                            )
)

body <- dashboardBody(

)

# Put them together into a dashboardPage
ui <- dashboardPage(
  dashboardHeader(title = "Padding demo",titleWidth=400),
  sidebar,
  body
)
server <- function(input, output) {


}
shinyApp(ui,server)

最佳答案

您的问题不是splitCells的填充-工作正常。这与输入周围也有填充有关。要删除它,您可以添加以下代码

body <- dashboardBody(
  tags$head(
    tags$style(
      ".shiny-input-container{padding:0px !important;}"
    )
  )
)


希望这可以帮助

10-06 12:29