'How to get the drop down menu values to correspond to the points on a ggplot2 in Shiny R

Im having issues with my graph changing values when I select a different value in my drop down menu. For example, in my inventory list I have a 'blouse' and 'jeans', when I select either one the points on my graph do not change. I want to points on the graph to correspond with the selected inventory. What am I doing wrong in the code?

ui <- fluidPage(
  titlePanel("Clothes Inventory"),
  sidebarLayout(
    sidebarPanel(
      selectInput(inputId = "CurrentInventory",  
      label = "1. Select Inventory Product",  
      choices = unique(df$CurrentInventory), selected = "Blouse"),
     dateRangeInput("dates", 
                     "2. Enter date range",
                     start = min(df$firstInventory), 
                     end = max(df$latestInventory))),
      textOutput("DateRange")
      ),
      
    textInput(inputId = "text", 
      label = "3. Enter Notes Here", ""),
    
  mainPanel(ui <- 
                            textOutput("mytext"),
                             plotOutput("myhist"),                             
                             tableOutput("mytable")
                             
                             )
      )
    

server <- function(input, output, session) {output$myhist <- renderPlot({
 
  ggplot(df, aes(x=  latestInventory, y = count),position = "blouse", stat = "count") + 
    geom_point( 
        data= df[df$currentInventory == input$CurrentInventory | df$firstInventory >= input$dates[1] & df$latestInventory <= input$dates [2]],
        colour = "black")})


output$mytext <- renderText(input$text)


                                   
datasetInput1 <- renderTable({
    df %>% filter(currentInventory == input$CurrentInventory)
  })
                                   
output$mytable <- renderTable(df)
   
                                   
}


Solution 1:[1]

Try the following:

server <- function(input, output, session) {
 
  myplot <- reactive({ 
     df %>% 
       dplyr::filter(currentInventory == input$CurrentInventory & firstInventory >= input$dates[1] & latestInventory <= input$dates[2]) %>% 
       ggplot(aes(x=  latestInventory, y = count),position = "blouse", stat = "count") +
       geom_point(colour = "black")
})

  output$myhist <- renderPlot( myplot() )
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1