I have a basic query for someone with knowledge of Shiny apps. My application has the following code, as you can see I added an abline (red line) to slide with the slider through the created graph. It turns out that I can't change the value in the slider to change the position of the red line on the graph. It seems to me that I am not correctly relating the ui and server part of this item. Anyone who can help me please?
library(shiny)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("prueba01 data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30),
sliderInput("line", "Red line:",
min = 0, max = max(faithful$waiting),
value = 71),
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot")
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$distPlot <- renderPlot({
# generate bins based on input$bins from ui.R
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins + 1)
line <- seq(min(x), max(x), length.out = input$line + 1)
# draw the histogram with the specified number of bins
hist(x, breaks = bins, col = 'darkgray', border = 'white', abline = mean,
xlab = 'Waiting time until next eruption (minutes)',
ylab = 'Frecuency',
main = 'Waiting time hist')
abline(v= 71,col="red")
})
}
# Run the application
shinyApp(ui = ui, server = server)
in the server part you have:
With that you are giving it a fixed value and not relating it to the one that is executed through the user interface
The correct is: