3

我想删除/减少 Shiny 中 selectinput 的标签和选择选项之间的空间。我还想减少两个不同的选择输入之间的空间。

我尝试将 selectinputs 包装为 div 样式并将边距和填充设置为 0。这没有效果,但我可能做错了。请参阅下面的代码。

ui <- fluidPage(
  theme = shinytheme("sandstone"),
  sidebarLayout(
    sidebarPanel(
      div(style = "font-size:12px; margin: 0px; padding: 0px",
        selectInput(
            "select1", 
            label = h5("Selection 1"),
            choices = c("a", "b", "c"), 
            selectize = TRUE
          ),
          selectInput(
            "select2", 
            label = h5("Selection 2"),
            choices = c("a", "b", "c"), 
            selectize = TRUE
          )
      )
    ),
    mainPanel(
    )
  )
)

server <- function(input, output, session) {}

shinyApp(ui, server)
4

2 回答 2

4

要减少标签和下拉列表之间的空间,请使用以下 CSS:

.shiny-input-container > label {margin-bottom: -15px;}

为了减少两个选择输入之间的空间,您可以在它们之间插入一个div带有负样式的margin-top

library(shiny)
library(shinythemes)

css <- "
.shiny-input-container > label {margin-bottom: -15px;}"

ui <- fluidPage(
  theme = shinytheme("sandstone"),
  tags$head(
    tags$style(HTML(css))
  ),
  sidebarLayout(
    sidebarPanel(
      selectInput(
        "select1", 
        label = h5("Selection 1"),
        choices = c("a", "b", "c"), 
        selectize = TRUE
      ),

      div(style = "margin-top:-15px"),

      selectInput(
        "select2", 
        label = h5("Selection 2"),
        choices = c("a", "b", "c"), 
        selectize = TRUE
      )
    ),
    mainPanel(
    )
  )
)

server <- function(input, output, session) {}

shinyApp(ui, server)
于 2019-09-11T10:09:14.180 回答
0

这是关于 Shiny 的链接 - 将下拉菜单(选择标签)的大小(填充?)变小

于 2019-09-05T15:27:25.977 回答