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.
library(shiny)
library(tidyverse)
# 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
sidebarLayout(
sidebarPanel(
sliderInput("muA",
"Mean of Dist A:",
min = 1,
max = 10,
step = 0.5,
value = 3),
sliderInput("muB",
"Mean of Dist B:",
min = 1,
max = 10,
step = 0.5,
value = 5),
sliderInput("sd",
"Standard Deviation:",
min = 1,
max = 10,
step = 0.5,
value = 5),
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("plot")
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output, session) {
observe({
updateSliderInput(session, "muB", value = ifelse(input$muA == input$muB,
ifelse(input$muA > 9, input$muB - 1, input$muB + 1),
input$muB))
})
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)