html - 设置 Shiny 的小部件与其标题(文本)之间的距离

标签 html css r shiny

我有一个简单 Shiny 的应用程序,它显示三个 colourInput() 按钮。我会减少每个按钮和它的标题之间的空白,以便更接近它。

enter image description here

 #ui.r
     library(shiny)
    library(shinydashboard)
    shinyUI( dashboardPage(
      dashboardHeader(
      title="Styling Download Button"
      ),
        dashboardSidebar(

          div(style="display: inline-block;vertical-align:top; width: 115px;",colourInput("rightcolor",h5("Left"), value = "#00B2EE")),
          div(style="display: inline-block;vertical-align:top; width: 115px;",colourInput("overlapcolor",h5("Overlap"), value = "#7CCD7C")),
          div(style="display: inline-block;vertical-align:top; width: 115px;",colourInput("leftcolor",h5("Right"), value = "#FFFACD")),


        ),
        dashboardBody()

    ))
    #server.r
    shinyServer(function(input, output) {

    })

最佳答案

您必须更改显示标题的 div 元素。一种方法是将 style 参数添加到 h5 函数。如果通过添加 style='margin: 0px'margin 减少到 0 像素,您将获得所需的结果(您也可以使用:margin-top margin-bottom 等)。

如果你想调整其他 Shiny 小部件,你总是可以将它们包装在 div 中并使用 style 参数调整它们(例如:div(style= '边距:0px;填充:15px;',selectInput(...)))。可以找到关于其他 div 参数的信息 here .

你的例子

library(shiny)
library(shinydashboard)
library(colourpicker)

# Create ui
ui <- shinyUI( dashboardPage(
  dashboardHeader(
    title="Styling Download Button"),
  dashboardSidebar(
    div(style="display: inline-block;vertical-align:top; width: 115px;",colourInput("rightcolor",h5("Left", style='margin: 0px;'), value = "#00B2EE")),
    div(style="display: inline-block;vertical-align:top; width: 115px;",colourInput("overlapcolor",h5("Overlap", style='margin: 0px;'), value = "#7CCD7C")),
    div(style="display: inline-block;vertical-align:top; width: 115px;",colourInput("leftcolor",h5("Right", style='margin: 0px;'), value = "#FFFACD"))),
  dashboardBody()
))

# Create Server
server <- shinyServer(function(input, output) {})

# Run app
shinyApp(ui, server)

关于html - 设置 Shiny 的小部件与其标题(文本)之间的距离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53282207/

相关文章:

html - 如何居中对齐圆圈?

jquery - 当我使用 val() 设置选择的值时,为什么不触发 jquery 更改事件?

jquery - z-index 问题

php - CMS 表单无法根据 css 正确显示

html - 网格布局中每个 block 的背景图像 - 在 html 中没有 css

html - 如何修复最大宽度和 float :left interaction

html - 如何在屏幕的左侧和右侧放置 Angular Material 单选按钮?

r - .Rd 链接到建议的包

r - 使用 NEAR 正则表达式搜索文本

r - mutate_if 的正确语法