how to plot R Shiny sliderInputs

Hi all,

I want to barPlot the input values of 2 sliders in my shiny web app. As the original code is lengthy I included a shortened example of what I am trying to build below.

The bars in the chart are supposed to be the values of the sliderInputs S1 and S2, but for that I would need to include them as a vector which I can´t figure out how to do. The code as below returns the error "object input ID not found" instead of displaying the barplot.

As I just started with Shiny I am still trying to properly understand reactive(), so please excuse my rookie attempt.

Any hints would be greatly appreciated - thanks a lot!

library(shiny)


data <- reactive(c({input$S1; input$S2}))
    

ui <- fluidPage(
    br(),
    sliderInput(inputId = "S1", label= "S1", min = 1, max = 10, value = 5),
    br(),
    sliderInput(inputId = "S2", label= "S2", min = 1, max = 10, value = 5),
    br(),
    plotOutput("P1", width = "40vw")
    
)



server <- function(input, output) {
    

    output$P1 <- renderPlot({
        barplot(data(), horiz=TRUE, names.arg=c("S2", "S1"))
    })


}

shinyApp(ui = ui, server = server)

As a general rule you should only use reactive within the server code. Outside of the server code it has no meaning.

1 Like

This topic was automatically closed 7 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.