Sorry, I don't know if the question is clear enough: In Shiny, every time the slider is sliding, it will only calculate and update the value at the end of the sliding. If I link its value to the chart, it doesn't look very smooth when sliding (the chart will only change when the mouse is released or after seconds, rather than keep changing with the sliding).
Use the slide bar to change the y, and the red point's position in the chart will be changed.
Part of my code is as follows:
In ui.R:
sliderInput("slider_mean",
HTML("Try to change the value of ŷ:"),
min = 1, max = 200, value = 100,width="30%"),
plotlyOutput('meanplot'),
In server.R:(This code may not be complete, just to give an example)
output$meanplot <- renderPlotly({
meantb <- data.frame(y_hat = 1:200) %>%
mutate(col2 =(y_mean1()-y_hat)^2+(y_mean2()-y_hat)^2+(y_mean3()-y_hat)^2+(y_mean4()-y_hat)^2+(y_mean5()-y_hat)^2+(y_mean6()-y_hat)^2)
#Here is to input the slider value
highlight_adjust <- meantb %>%
filter(y_hat %in% input$slider_mean)
p=ggplot(meantb,
aes(x = y_hat, y = col2)) +
geom_point(size =0.7,color="black") +
geom_point(data=highlight_adjust,
aes(x = y_hat, y = col2),
color='red')+
geom_line(size = 0.2,color="black") +
ggplotly(p)
})
The example from Shiny:
https://shiny.rstudio.com/gallery/slider-bar-and-slider-range.html
If we move the slider bar quickly, the output value will have a delay.