css - 在 Shiny 中删除/隐藏 sliderInput 的小刻度

标签 css r shiny

我希望从 sliderInput() 中删除/隐藏次要刻度(不是主要刻度)。例如,在 Shiny 应用程序的默认示例 - Old Faithful Geyser Data 中,有一个 sliderInput() 可以为直方图选择多个 bin。 bins 的数量总是整数。因此,最好在 sliderInput() 中隐藏/删除次要刻度,而只显示 bin 编号的主要刻度。

Shiny 应用程序的默认示例:

library(shiny)

# Define UI for application that draws a histogram
ui <- fluidPage(

   # Application title
   titlePanel("Old Faithful Geyser Data"),

   # Sidebar with a slider input for number of bins 
   sidebarLayout(
      sidebarPanel(
         sliderInput("bins",
                 "Number of bins:",
                 min = 1,
                 max = 10,
                 value = 1)
      ),
  
     # Show a plot of the generated distribution
     mainPanel(
        plotOutput("distPlot")
     )
  )
)

# Define server logic required to draw a histogram
server <- function(input, output) {

   output$distPlot <- renderPlot({
   # generate bins based on input$bins from ui.R
   x    <- faithful[, 2] 
   bins <- seq(min(x), max(x), length.out = input$bins + 1)
  
   # draw the histogram with the specified number of bins
   hist(x, breaks = bins, col = 'darkgray', border = 'white')
   })
}

# Run the application 
shinyApp(ui = ui, server = server)

我在 sliderInput() 中尝试过 tick = FALSE ,如下所示:

sliderInput("bins", 
             label = "Number of bins:", 
             min = 1,
             max = 10,
             value = 1,
             ticks = FALSE)

但是,这会从 sliderInput() 中删除所有刻度(包括主要刻度)。

最佳答案

您可以使用 tags$style(type = "text/css", ".irs-grid-pol.small {height: 0px;}") 覆盖 CSS。 CSS 可以在这里找到:https://github.com/IonDen/ion.rangeSlider/issues/171 .

生成的 sliderInput() 仅显示整数的刻度:

shinyApp(
  ui <- fluidPage(
    tags$style(type = "text/css", ".irs-grid-pol.small {height: 0px;}"),
    sliderInput("bins", "Number of bins:", 1, 10, 1)
  ),
  server <- function(input, output) {}  
)

关于css - 在 Shiny 中删除/隐藏 sliderInput 的小刻度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44474099/

相关文章:

html - 适用于宽度和高度的媒体查询

r - 如何以交替顺序在 R 中使用矢量化函数?

r - 让用户在 Shinydashboard 应用程序中创建不同的按钮操作

r - 第一个 Shiny 应用程序出错

r - 统计这个因子中 "0"的个数

jquery - 使用 Shiny 中的本地语言文件进行数据表国际化

javascript - 哪个 JavaScript 代码实现了 shiny 的 numericInput 小部件?

jquery - 调整大小后 100% 高度 div 向上滚动

html - 表格标签占用的高度高于父 div 提到的高度

javascript - @HostBinding 从子组件 Angular 4 禁用类