【问题标题】:Control the appearance of a sliderInput in Shiny在 Shiny 中控制滑块输入的外观
【发布时间】:2016-03-21 17:43:21
【问题描述】:

我正在尝试在 Shiny 中控制滑块输入的大小和外观。具体来说,我已经把它做得更大更宽,并改变了滑块的背景颜色。我想让滑块的末端变成正方形,删除出现在滑块下方的刻度线,然后将值 (1:10) 放在条的主体内以白色显示。我试图操纵 CSS,但只取得了适度的成功。滑块更大更宽,但栏的一侧是方形的,我无法移动文本。显然,我的 CSS 技能低于标准。我已经查阅了各种教程,但无法破解它们。任何帮助将不胜感激,因为我真的被困住了。

这是我尝试过的:

 ui <- fluidPage(

   tags$style(HTML(".irs-bar {width: 100%; height: 25px; background: black; border-top: 1px solid black; border-bottom: 1px solid black;}")),
   tags$style(HTML(".irs-bar-edge {background: black; border: 1px solid black; height: 25px; border-radius: 15px 15px 15px 15px;}")),
   tags$style(HTML(".irs-line {border: 1px solid black; height: 25px;}")),
   tags$style(HTML(".irs-grid-text {font-family: 'arial'; color: black}")),
   tags$style(HTML(".irs-max {font-family: 'arial'; color: black;}")),
   tags$style(HTML(".irs-min {font-family: 'arial'; color: black;}")),
   tags$style(HTML(".irs-single {color:black; background:#6666ff;}")),              

   uiOutput("testSlider")

    )

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

              output$testSlider <- renderUI({
                                           sliderInput( 
                                                      inputId="test",
                                                      label=NULL,
                                                      min=1,
                                                      max=10, 
                                                      value=5,
                                                      step = 1,
                                                      width='100%'
                                                      ) # close slider input          
                                            }) # close renderUI

  }

 shinyApp(ui = ui, server=server)

【问题讨论】:

  • 要删除刻度,sliderInput( ) 中有一个ticks 参数,将其设置为FALSE
  • 请记住,如果您让sliderInput(...) 包装器像这样处理ticks 参数,您也会丢失数字/日期文本。更好的是 (imo) 让 CSS 标签处理文本和刻度的微调。

标签: css r shiny


【解决方案1】:

怎么样?

 ui <- fluidPage(
    tags$style(type = "text/css", "
      .irs-bar {width: 100%; height: 25px; background: black; border-top: 1px solid black; border-bottom: 1px solid black;}
      .irs-bar-edge {background: black; border: 1px solid black; height: 25px; border-radius: 0px; width: 20px;}
      .irs-line {border: 1px solid black; height: 25px; border-radius: 0px;}
      .irs-grid-text {font-family: 'arial'; color: white; bottom: 17px; z-index: 1;}
      .irs-grid-pol {display: none;}
      .irs-max {font-family: 'arial'; color: black;}
      .irs-min {font-family: 'arial'; color: black;}
      .irs-single {color:black; background:#6666ff;}
      .irs-slider {width: 30px; height: 30px; top: 22px;}
    "),
    uiOutput("testSlider")
  )

  server <- function(input, output, session){
    output$testSlider <- renderUI({

      sliderInput(inputId="test", label=NULL, min=1, max=10, value=5, step = 1, width='100%')

    })
  }

 shinyApp(ui = ui, server=server)
  • 滑块的末端是irs.bar, .irs-bar-edge {border-radius: 0px}
  • 通过设置.irs-grid-pol {display: none;} 删除刻度。
  • 白色和内部的刻度数字是.irs-grid-text {color: white; bottom: 17px; z-index: 1},其中z-index 使数字位于条本身上方的一层。
  • 我还添加了.irs-slider {width: 30px; height: 30px; top: 22px;} 来调整滑块旋钮。

【讨论】:

  • 有没有办法用css定位滑块输入?我想把它们并排包装起来。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-11-06
  • 2023-03-03
  • 1970-01-01
  • 1970-01-01
  • 2015-10-16
  • 1970-01-01
  • 2020-07-08
相关资源
最近更新 更多