library(shiny)

a <- data.frame(a)

Define UI for application that draws a histogram

ui <- fluidPage(

# Application title
titlePanel("Old Faithful Geyser Data"),

# Sidebar with a slider input for number of bins 
sidebarLayout(
    sidebarPanel(
        sliderInput("Ideology",
                    "Ideology (1- Very Liberal ; 5- Very Conservative:)",
                    min = 1,
                    max = 5,
                    value = 3)
    ),

    # 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({
    # Aqui esta o truque: Utilize o comando filter para fazer com que o input$Ideology torne o gráfico dinâmico
    ggplot(filter(a, ideo5==input$Ideology), aes(x=pid7)) + geom_histogram(binwidth = 0.25) + xlab("7 Point Party")
})

}

Run the application

shinyApp(ui = ui, server = server)