我希望从 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/