【问题标题】:Removing/hiding minor ticks of a sliderInput in Shiny在 Shiny 中删除/隐藏滑块输入的小刻度
【发布时间】:2017-06-10 13:54:28
【问题描述】:

我希望从sliderInput() 中删除/隐藏次要刻度(不是主要刻度)。例如,在 Shiny 应用程序的默认示例 - Old Faithful Geyser Data 中,有一个 sliderInput() 可以选择直方图的多个 bin。箱数始终是整数。因此,最好隐藏/删除 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() 中的所有刻度(包括主要刻度)。

【问题讨论】:

    标签: css r shiny


    【解决方案1】:

    您可以使用 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) {}  
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多