【问题标题】:Horizontal Rule hr() in R Shiny SidebarR Shiny Sidebar中的水平规则hr()
【发布时间】:2017-09-21 09:00:39
【问题描述】:

在 Shiny 中使用 fluidRow() 时,通常可以在 UI 元素下使用 hr() 制作水平线,但不能在文本下的 sideBarPanel() 中使用。如何制作水平线或其他类似的规则来划分边栏中的文本和 UI 元素?

【问题讨论】:

  • 跟随this answer 会做:tags$hr(style="border-color: black;")

标签: css r shiny


【解决方案1】:

一般来说,线条是可见的,但与背景的对比度非常低。 为了使该行更加可见,您可以通过在 ui 部分中包含以下内容来修改 CSS 代码:

  tags$head(
    tags$style(HTML("hr {border-top: 1px solid #000000;}"))
  ),

使用tags$style(HTML(...)),您可以在应用中包含 CSS。该行的 html 标记是 hr。其余参数表示线的选择、宽度、颜色等规格。

完整的工作示例见下文:

library(shiny)
    
ui <- fluidPage(
  tags$head(
    tags$style(HTML("hr {border-top: 1px solid #000000;}"))
  ),
   sidebarLayout(
      sidebarPanel(
         "text",
         hr(),
         uiOutput("out")
      ),
      mainPanel(
         plotOutput("distPlot")
      )
   )
)

server <- function(input, output) {
  output$out <- renderUI({
    sliderInput("bins",
                "Number of bins:",
                min = 1,
                max = 50,
                value = 30)
  })
}


shinyApp(ui = ui, server = server)

12.2020 更新: 来自 David Ranzolin 的评论,请参阅评论部分。

您也可以直接将样式参数传递给 hr(),例如:hr(style = "border-top: 1px solid #000000;")

【讨论】:

  • 我看到了问题。 hr() 以非常浅的灰色创建规则,在侧边栏的灰色中很难看到。有没有办法改变它的颜色?
  • 漂亮!非常感谢。
  • 您也可以直接将样式参数传递给 hr(),例如:hr(style = "border-top: 1px solid #000000;")
  • 很好,我将它添加到答案中。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-02-23
  • 1970-01-01
  • 1970-01-01
  • 2013-05-18
  • 2010-09-18
  • 2012-07-02
相关资源
最近更新 更多