rstudio / shiny

Easy interactive web applications with R
https://shiny.posit.co/
Other
5.37k stars 1.87k forks source link

sliderInput step behavior is surprising #2159

Open srtg4we5gsetrgwhreyt opened 6 years ago

srtg4we5gsetrgwhreyt commented 6 years ago

app.txt

For the attached app (change .txt to .R to run) there is an issue when I try to update a sliders step size from 0.5 to 1 using the updateSliderInput command, it seems to not be able to get the slider back to the original value.

Steps to reproduce issue:

  1. Run the app.R code in browser (I am using latest version of Chrome)
  2. Change the value from 3 to 3.5
  3. Click the 'Toggle Step Size' checkbox
  4. Move the slider from 4 to 5
  5. Then try to go back to 4, it skips right past 4 and goes from 3 to 5.
wch commented 6 years ago

The example from above:

library(shiny)

ui <- fluidPage(mainPanel(
    sliderInput("lenval1", "Length #1:", min = 0.5, max = 24, value = 3 , step = 0.5),
    checkboxInput("checkboxin","Toggle Step Size")
  )
)

server <- function(input, output, session) {
  observeEvent(input$checkboxin,{
    if (isTRUE(input$checkboxin)) {
      updateSliderInput(session, "lenval1", label = NULL, value=NULL,min = NULL, max = NULL, step = 1)
    }
    else {
      updateSliderInput(session, "lenval1", label = NULL, value=NULL,min = NULL, max = NULL, step = 0.5)
    }
  })
}

shinyApp(ui = ui, server = server)
jcheng5 commented 6 years ago

Investigate-only for v1.2

jcheng5 commented 6 years ago

This seems to have nothing to do with updating, and everything to do with the min, max, and step sizes. Here's a minimal repro:

library(shiny)

ui <- fluidPage(
  sliderInput("lenval1", "Length #1:", min = 0.5, max = 24, value = 3 , step = 1)
)

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

shinyApp(ui = ui, server = server)
jcheng5 commented 6 years ago

I was not surprised that something weird happens with min = 0.5, max = 24, step = 1, as max == min + x * step isn't true for any integral value of x. But I was surprised to find that if min = 0.5, max = 24.5, step = 1, then the slider will let you select any value in c(0.5, 2:24, 24.5)--it doesn't snap to the 0.5 values which is slightly surprising to me, and skips 1 which is even more surprising.

jcheng5 commented 6 years ago

@shalutiwari @alandipert @schloerke I'm dropping this from v1.2, this could be bundled into other slider improvement work though.

wch commented 6 years ago

Looks like an issue with ion.rangeSlider: http://jsfiddle.net/winstonchang/36e4akxj/

EthanStevensUSGS commented 6 years ago

Adding to this thread, in reference to a question asked on SO [here].(https://stackoverflow.com/questions/53197208/r-shiny-sliderinput-shows-repeated-values)

In this example we are using updateSelectInput and inputting an expression into the max argument, this is causing the steps to repeat, and the slider to be, what I am guessing, stuck on the previous steps. I am not sure if this is b/c you are not supposed to pass expressions to this function, or if it is part of this bug

library(shiny)

ui <- fluidPage(

  sidebarLayout(
    sidebarPanel(
    sliderInput(inputId="numberOfElements",
                label = "Number of elements to delete",
                #values updated dynamically on server.r
                min = 1, 
                max = 5, value = 1, step = 1),
    actionButton("button","Create Bug")
    ),

    mainPanel(
    )))

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

      observeEvent(input$button,{

        updateSliderInput(session,
                          "numberOfElements",
                          min=1,
                          max = 5-1,
                          value = 0,
                          step=1)
      })
}

shinyApp(ui = ui, server = server)

EDIT: This issue is also present w/o an expression, e.g. max=4 in the updateSelectInput

jcheng5 commented 6 years ago

@EthanStevensUSGS This seems like a different, and worse, issue. It looks to me like the tick marks don't change, nor the number or position of the tick labels; the tick labels are just updated to round numbers. Try changing max to various numbers; the numbers are almost but not quite right.

jcheng5 commented 6 years ago

@EthanStevensUSGS I opened a separate issue #2254. Thanks for the report.