如何在有光泽的情况下向sliderInput()添加加号和减号箭头?

时间:2016-12-06 20:51:15

标签: r shiny

我正在开发一款闪亮的应用程序,并且希望提高滑块的精确度(滑块的范围从0到1000,并且很难通过步长1来精确调整滑块)。我无法在任何地方找到答案。 这是我的一个滑块的代码:

sliderInput("mean2", "", min=0, max=1000, value=500, step=1)

1 个答案:

答案 0 :(得分:2)

尝试安排您的代码:

library(shiny)

ui <- fluidPage(

  # Application title
  titlePanel("Old Faithful Geyser Data"),
  actionButton("minus", "Minus"),
  actionButton("plus", "Plus"),
  # Sidebar with a slider input for number of bins
  sidebarLayout(
    sidebarPanel(
      sliderInput("mean2",
                  "Number of bins:",
                  min = 0,
                  max = 1000,
                  value = 500,
                  step= 1)
    ),

    # Show a plot of the generated distribution
    mainPanel(
      plotOutput("distPlot")
    )
  )
)

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

  v <- reactiveValues(data = 500)

  observeEvent(input$minus, {
    v$data <- input$mean2 - 1
    updateSliderInput(session,"mean2", value = input$mean2 - 1)
  })

  observeEvent(input$plus, {
    v$data <- input$mean2 + 1
    updateSliderInput(session,"mean2", value = input$mean2 + 1)
  })  

  observeEvent(input$mean2, {
    v$data <- input$mean2
  })

  output$distPlot <- renderPlot({

    # generate bins based on input$bins from ui.R
    x    <- faithful[, 2]
    bins <- seq(min(x), max(x), length.out = v$data + 1)

    # draw the histogram with the specified number of bins
    hist(x, breaks = bins, col = 'darkgray', border = 'white')

  })

}

shinyApp(ui, server)