在Shiny中删除/隐藏sliderInput的次要刻度

时间:2017-06-10 13:54:28

标签: css r shiny

我希望从sliderInput()删除/隐藏次要标记(不是主要标记)。例如,在Shiny app - Old Faithful Geyser Data的默认示例中,有一个sliderInput()可以为直方图选择多个bin。箱数总是整数。因此,隐藏/删除sliderInput()中的次要刻度并且只显示二进制数的主要刻度是很好的。

Shiny app的默认示例:

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)

我在tick = FALSE中尝试过这样的sliderInput()

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

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

感谢先进的所有帮助。

1 个答案:

答案 0 :(得分:3)

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

结果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) {}  
)