Error with Shiny updateSliderInput

Hello R Studio Community,
I understand this is not currently a reproducible example, but maybe I can describe the issue that I am having and there will be a simple way to fix it, that I am overlooking. Below is the code for shiny app to have a slider updated, such that the values of sliders "muA" and "mu0" can't be equal. When run, the slider will go haywire and not let the user change values, oscillating back and forth between two values. How can I update this updateSliderInput() fx such that this doesn't happen?

        updateSliderInput(session, "muA", value = ifelse(input$mu0 == input$muA,
                                                         ifelse(input$mu0 == 3, input$muA - 0.5, input$muA + 0.5),

Link to app:

Thank you,
Will Baker-Robinson

You're probably going to need to provide a reproducible example in order for anybody to solve the issue. The code you gave does not reproduce the problem, even when I put it in a shiny app.

I created the following example but was not able to replicate the error. I could share all the code for my project, along with the link to my app, but that seems too unwieldy to try to sort through. The error that I get in my rshiny project is there are times when observe updates the slider, and then the slider continuously jumps back and forth in-between two values, and the user is unable to change the slider anymore.


# Define UI for application that draws a histogram
ui <- fluidPage(

    # Application title
    titlePanel("Reproducible Example - Slider Issue"),

    # Sidebar with a slider input for number of bins 
                        "Mean of Dist A:",
                        min = 1,
                        max = 10,
                        step = 0.5,
                        value = 3),
                        "Mean of Dist B:",
                        min = 1,
                        max = 10,
                        step = 0.5,
                        value = 5),
                        "Standard Deviation:",
                        min = 1,
                        max = 10,
                        step = 0.5,
                        value = 5),

        # Show a plot of the generated distribution

# Define server logic required to draw a histogram
server <- function(input, output, session) {
        updateSliderInput(session, "muB", value = ifelse(input$muA == input$muB,
                                                         ifelse(input$muA > 9, input$muB - 1, input$muB + 1),
    output$plot <- renderPlot({
        from <- -9
        to <- -9
        if(input$muA > input$muB){
            from <- input$muB - 4.5*input$sd
            to <- input$muA + 4.5*input$sd
        } else{
            from <- input$muA - 4.5*input$sd
            to <- input$muB + 4.5*input$sd
        data <- tibble(x_val = seq(from, to, 0.1),
                       pdf_muA = dnorm(x_val, mean = input$muA, sd = input$sd),
                       pdf_muB = dnorm(x_val, mean = input$muB, sd = input$sd))
        ggplot(data) +
            geom_line(mapping = aes(x = x_val, y = pdf_muA), 
                      color = "red") +
            geom_line(mapping = aes(x = x_val, y = pdf_muB),
                      color = "green")

# Run the application 
shinyApp(ui = ui, server = server)

If this code does not reproduce the error, it likely won't be useful for me or others to help with your issue.

In order for anyone to help, you must do the first step of creating a reproducible example. It does take time and effort, but often the hardest part of solving an issue is simply isolating it. It's a step that must be done.

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.